Web Development using node. JS (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.