Node.js


John Alexis Guerra Gómez


Slides:http://johnguerra.co/lectures/webDevelopment_fall2020/06_Node/

Class page:http://johnguerra.co/classes/webDevelopment_spring_2020/

What did we learn last time?

Readings discussion

  • questions?

Random Questions

  • What is Node.js?
  • Why would we need Node.js?
  • What does it mean it is asynchronous?

Node.js

Interactive Shell

$ node

Node.js

Some things work only on the browser, some only on the server

NPM

Install a package

$ npm install express

Creates a local node_modules/ folder

Install it globally

$ npm install -g express

Installs it for the whole system

Install and save dependency

# Run only once
$ npm init
# Then for each package
$ npm install --save express

Installs it locally and creates a packages.json file that saves the dependency

packages.json

{
  "name": "webdevex1",
  "version": "1.0.0",
  "description": "TEst",
  "main": "index.js",
  "dependencies": {
    "express": "^4.14.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/john-guerra/webDevEx1.git"
  },
  "author": "John Alexis Guerra Gómez",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/john-guerra/webDevEx1/issues"
  },
  "homepage": "https://github.com/john-guerra/webDevEx1#readme"
}

Express

Allows us to create a simple HTTP Server

http://expressjs.com/