Nodejs Framework express4.x Learning--Installation Chapter

Source: Internet
Author: User

I. Installation and establishment of the project

1, installation Nodejs

2. Install Express (Global)

NPM Install-g Express

The default installation is 4.12.4

3, because the project builder is split separately after version 3.6, it also needs to be installed separately (global)

NPM install-g Express-generator

You can see the version of Express after you install it.

EXPRESS-V # Check the version of Express

4. Enter the working directory to create a project through Express

D:\>CD workspace/uedfe/www/express/&& express-e myexpress   create:myexpress   create:myexpress/ Package.json   create:myexpress/app.js   create:myexpress/public   create:myexpress/public/stylesheets   create:myexpress/public/stylesheets/   create:myexpress/public/images   create:myexpress/views   Create:myexpress/views/index.ejs   create:myexpress/views/error.ejs   create:myexpress/routes   Create : Myexpress/routes/index.js   create:myexpress/routes/users.js   create:myexpress/bin   Create: Myexpress/bin/www   Install dependencies:     > CD myexpress && npm install   run the app:     > SET debug=myexpress:* & npm start   create:myexpress/public/javascripts

Express-e myexpress

This sentence I understand is the template for Ejs, if not with this parameter or-j that template will be used jade.

5. Enter the project directory and install the dependencies

Package.json files are automatically generated when the project directory is generated by express and need to be installed yourself

CD myexpress && NPM Install

6. Modify the Ejs template file suffix to html

Open App.js

Find--app.set (' View engine ', ' Ejs '); Replace with-->app.engine ('. html ', ejs.__express); App.set (' View engine ', ' html ');

and change the template file suffix in the View folder to HTML.

II. directory Structure

    • Bin, the script file that holds the startup project
    • Node_modules, store all project dependent libraries.
    • Public, static file (css,js,img)
    • Routes, routing files (C,controller in MVC)
    • Views, page files (ejs templates)
    • Package.json, Project dependent configuration and developer information
    • App.js, applying the core configuration file

Third, start the service

NPM start

You can see the first page.

Nodejs Framework express4.x Learning--Installation Chapter

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.