- Great performance
- Asynchronous and event driven
- Single threaded
- Node package manager (npm) provides access to thousands of reusable packages.
ExpressExpress is an un-opinionated, minimalist web framework for Node.js
Setting up the Node environment
- Install Node $ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
$ sudo apt-get install -y nodejs
$ node -v
- Install express generator The express application generator tool generates an Express application skeleton.
$ npm install express-generator -g
(-g flag installs the tool globally)
- Create skeleton project $ express --ejs --git hellonode
$ cd hellonode
$ npm install
$ DEBUG=hellonode:* npm start
then go to browser and enter http://localhost:3000/
- Enable server restart on file changes $ npm install --save-dev nodemon
then update the scripts section as below,
"start": "node ./bin/www",
"devstart": "nodemon ./bin/www"
$ npm run devstart
- Directory structure Let's have a look at the generated files.
defines the application dependencies and other information
express: express framework
body-parser: parses the body portion of an incoming HTTP request and makes it easier to extract different parts of the contained information.
cookie-parser: uses to parse the cookie header.
morgan: HTTP request logger
ejs: view template engine
nodemon: enable server restart
>> www file
application entry point
sets up the application with various settings and middlewares.
Congratulations!!! you just created your first website which runs using Node!!!