Getting Setup

Table of Contents

Installation

node -v
v8.11.1

Introduction

node
> console.log('Hello World');
Hello World
undefined
> console.log('Hello World');
Hello World
undefined

Why Node.js?

Non-blocking I/O

Blocking I/O

var getUserSync = require('./getUserSync');
var user1 = getUserSync('123');
console.log('user1', user1);
var user2 = getUserSync('321');
console.log('user2', user2);
var sum = 1 + 2;
console.log('The sum is ' + sum);

Alt text

Non-Blocking I/O

var getUser = require('./getUser');
getUser('123', function (user1) {
console.log('user1', user1);
});
getUser('321', function (user2) {
console.log('user2', user2);
});
var sum = 1 + 2;
console.log('The sum is ' + sum);

Alt text

Remark

NPM

Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Example: Validate Object


Atom Editor

Hello World

app.js

console.log('Hello World!');

Terminal

cd Desktop/hello-world/
ls
app.js
node app.js
Hello World!