Use Express

Express is the most popular Web development framework created by TJ, and the latest version of it is 4.x.

Hello World in Express

Here is a simple snippet code using Express, return a string Hello World via method res.send():

  1. var express = require('express');
  2. var app = express();
  3. app.get('/',function(req, res){
  4. res.send('Hello World');
  5. });
  6. app.listen(3000,function(){
  7. console.log('Express server started.');
  8. });

Run app.js:

  1. node app.js

Express generator

Express also provide a tool to generate project in seconds like other popular web frameworks: Express Generator

  • Install
  1. npm install -g express-generator
  • Generate project
  1. express test

Enter the folder and install all the dependencies:

  1. cd test && npm install

Now you are able to run this project with npm start. Awesome!