What is Node.js?
Download and install Node.js from the following link: https://nodejs.org/download/
Node.js – npm
Node Package Manager (npm) provides following two main functionalities:
- Online repositories for node.js packages/modules which are searchable on search.nodejs.org
- Command line utility to install Node.js packages, do version management and dependency management of Node.js packages.
npm comes bundled with Node.js installables after v0.6.3 version. To verify the same, open console and type following command and see the result:
$ npm -v
Node.js – Express Framework
Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates a rapid development of Node based Web applications.
Firstly, install the Express framework globally using npm so that it can be used to create web application using node terminal.
$ sudo npm install -g express-generator
Create your first express application
Step 1:Type express <app_name> in command line to create to your first app.This will create a new folder with name app_name in the current directory.
$ express sample
Step 2:Install the dependencies. These are the packages that are associated with the app. Jade is used to create the front end by default. npm install is used to install all the dependencies and is saved in the packages folder in your application folder.
Step 3:Run the app.When you run the app you will get a message “sample:server Listening on port 3000 +0ms” on the command line.Now open the browser and go to localhost/3000 to see the app.
$ DEBUG=sample:* npm start