STEP 1 – INSTALLATION NODE JS

OPERATING SYSTEMINSTRUCTIONS
OS XThe easiest way to install Node.js on OS X is to use the official installer from nodejs.org. You can also use Homebrew if you prefer.
WindowsThe easiest way to install Node.js on Windows is the official installer from nodejs.org. You can also use Chocolatey if you prefer.
LinuxThe exact instructions to install Node.js vary by distribution. Find instructions for yours here.

 

STEP 2 – CREATE A NEW PROJECT WITH “NPM INIT”

Create a new directory in your development environment and run npm init You’ll then answer a few basic questions about your project, and npm will create a new package.json file for you when you’re done.

PS E:\Projects\demo-project> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
name: (demo-project)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to E:\Projects\demo-project\package.json:

{
  "name": "demo-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

STEP 3 INSTALL EXPRESS

Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.

First let’s express install

npm install express --save
PS E:\Projects\demo-project> npm install express --save
demo-project@1.0.0 E:\Projects\demo-project
`-- express@4.15.3
  +-- accepts@1.3.3
  | +-- mime-types@2.1.15
  | | `-- mime-db@1.27.0
  | `-- negotiator@0.6.1
  +-- array-flatten@1.1.1
  +-- content-disposition@0.5.2
  +-- content-type@1.0.2
  +-- cookie@0.3.1
  +-- cookie-signature@1.0.6
  +-- debug@2.6.7
  | `-- ms@2.0.0
  +-- depd@1.1.0
  +-- encodeurl@1.0.1
  +-- escape-html@1.0.3
  +-- etag@1.8.0
  +-- finalhandler@1.0.3
  | `-- unpipe@1.0.0
  +-- fresh@0.5.0
  +-- merge-descriptors@1.0.1
  +-- methods@1.1.2
  +-- on-finished@2.3.0
  | `-- ee-first@1.1.1
  +-- parseurl@1.3.1
  +-- path-to-regexp@0.1.7
  +-- proxy-addr@1.1.4
  | +-- forwarded@0.1.0
  | `-- ipaddr.js@1.3.0
  +-- qs@6.4.0
  +-- range-parser@1.2.0
  +-- send@0.15.3
  | +-- destroy@1.0.4
  | +-- http-errors@1.6.1
  | | `-- inherits@2.0.3
  | `-- mime@1.3.4
  +-- serve-static@1.12.3
  +-- setprototypeof@1.0.3
  +-- statuses@1.3.1
  +-- type-is@1.6.15
  | `-- media-typer@0.3.0
  +-- utils-merge@1.0.0
  `-- vary@1.1.1

npm WARN demo-project@1.0.0 No description
npm WARN demo-project@1.0.0 No repository field.

STEP 4 – CREATE APP.JS

Create a file named app.js and add the following code:

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

Run the app with the following command:

node app.js

Then, load http://localhost:3000/ in a browser to see the output.

Use the applIcatIon generator tool, express-generator, QUICKLY CREATE AN APPLICATION

install express application generator.

npm install express-generator -g
PS E:\Projects> express --view=ejs myapp

   create : myapp
   create : myapp/package.json
   create : myapp/app.js
   create : myapp/routes
   create : myapp/routes/index.js
   create : myapp/routes/users.js
   create : myapp/public
   create : myapp/views
   create : myapp/views/index.ejs
   create : myapp/views/error.ejs
   create : myapp/bin
   create : myapp/bin/www
   create : myapp/public/stylesheets
   create : myapp/public/stylesheets/style.css

   install dependencies:
     > cd myapp && npm install

   run the app:
     > SET DEBUG=myapp:* & npm start

   create : myapp/public/images
   create : myapp/public/javascripts
.
├── app.js
├── bin
│   └── www
├── package.json
├── public
│   ├── images
│   ├── javascripts
│   └── stylesheets
│       └── style.css
├── routes
│   ├── index.js
│   └── users.js
└── views
    ├── error.ejs
    └── index.ejs

7 directories, 7 files