Full-Stack Web Development with Vue.js and Node

(singke) #1
Building an Express Application Chapter 2

Understanding Node.js


Before diving into Node.js programming, let's first look into some fundamentals of Node.js.


Node.js runs on the JavaScript V8 engine. The JavaScript V8 engine was built by The


Chromium Project for Google Chrome and Chromium web browsers. It is an open source
project written in C++. This engine is used for both client- and server-side web applications


with JavaScript.


Node.js programming


Let's start by running a node process. Open the Terminal and type this command:


$ node

This will start a new node process. We can write normal JavaScript here.


So, for example, we can write in the new Node shell the following JavaScript command:


> var a = 1;

It returns 1 when we type a and press enter.


We can also run a file with the .js extension in a node process. Let's create a folder


called tutorial in the root directory with the command mkdir tutorial and create a


file inside it called tutorial.js.


Now, in the Terminal, let's go into that directory with the following command:


$ cd tutorial
$ node tutorial.js

We should see something similar to the following:


This does not return anything because we haven't written anything for tutorial.js yet.


Now, let's add some code to the tutorial.js:


console.log('Hello World');
Free download pdf