INTRO TO�NODEJS
There’s no sleep() in Javascript.
01
03
02
04
TABLE OF CONTENTS
Overview
Assignment
Features of the topic
About the Topic
INTRODUCTION
Node.js is an open-source and cross-platform JavaScript runtime environment.
NODEJS TIMELINE
The Big Fork
io.js is a major fork of Node.js, with the goal of introducing ES6 support and moving faster
2009
2011
2014
2015
Javascript
Single Threaded
Huge Ecosystem
Use the newest ECMAScript standards
NodeJS
ADVANTAGES
Why should I use NodeJS?
Allows developers to use the same language in both the front end and the back end
Allows handling thousands of concurrent connections without the burden of managing thread concurrency, I/O Callbacks
npm has more than 1.3 million packages
You are in charge of deciding which ECMAScript version to use by the installed nodejs version (instead of polyfilling like in the browser)
NODEJS vs The Browser
| NodeJS | Browser |
APIs | Filesystem, standard library | DOM, Platform APIs |
Modules | CommonJS, ESM in modules | Bundlers, ESM in modules |
Control over the environment | Yes | No, the user’s browser is the env |
Global scope | global | winodw |
CommonJS
ES Modules(node 13+)
Modules
math.js:
module.exports = {
add: (a, b) => a + b
}
index.js
const math = require(‘./math’);
const ten = math.add(6, 4);
math.js:
export const add = (a, b) => a + b;�
export default { add };
index.js
import math, { add } from ‘./math’;
const ten = math.add(6, 4);
const eleven = add(7, 4);
// in an async function
const dynamicMath = await import(‘./math’);
.mjs or type: ‘module’
NATIVE MODULES
Node-gyp is a tool compiling native c++ addon modules for Node.js
Instead of compiling we can download prebuilt binaries for our OS
NODE REPL (Interactive shell)
node command in the terminal - like F12 in the browser
Building a web server
http module
ExpressJS
Hapi
Fastify
Building a web server
USING THE HTTP MODULE
http module
ExpressJS
Hapi
Fastify
Building a web server
USING ExpressJS
http module
ExpressJS
Hapi
Fastify
EVENT DRIVEN PROGRAMMING
EXERCISE
We’ll build a simple nodejs app capable of converting strings to and from base64
Thanks for listening!
Do you have any questions?