2.1 Installing Express
If a package is a dependency of a project, then we need to install the package in local mode in the project directory, and if you want to invoke the command in this package from the command line, you need to install it in global mode. Express provides a tool for quickly building projects on the command line, so we use global installation:
$ NPM Install-g Express
2.2 Establishment of the project
Express when initializing a project, you need to specify a template engine that establishes the project's basic structure with the following command:
Express Demo
In the current directory, a subdirectory demo appears, and some files are generated.
The default template for Nodejs is jade, too complex, and not HTML-based, and the cost of learning and front-end adaptation is huge. While Ejs is simple, it does not support template import, and performance is general. Swig syntax is simple, the learning cost is low, we choose Swig template here.
You will then need to install the default dependencies:
$ CD Demo
$ NPM Install
2.3 Starting the server
The website implemented with Express is actually a node. JS program that can be run directly:
$ node App.js
or start with NPM (with Debug):
$ set Debug=demo & NPM start
See Express server listening on port development mode. Open your browser and enter http://localhost:3000 to see a simple Welcome to express page.
Web Development using node. JS (ii)