Configure the Express framework in node. js

Source: Internet
Author: User
Tags install node

Play node. js, don't play backstage that's killing the chicken sledgehammer, it's fine today. Experience of developing node. JS Backstage

1. First install node. js and CNPM, I'm not going to say it here, look at my other article in node. js Installation and Configuration

To install the Express framework:

sudo cnpm install express-g

Global Installation Express,

After installing the Express generator, you can install it with the following statement

sudo cnpm install-g express-generator

At this point you can enter

Express-v

Check out the version of the Express frame you've installed,

Open the folder where you want to put the project, enter

  

Express-File name

You can create a new Express project and then install dependent

CNPM Install

And then enter

NPM start

Start the project, open the browser, enter in the address bar

127.0. 0.1:

At this point, the page will display "Welcome express" words that you have been installed successfully,

Open Project under the View Discovery suffix name is jade, what situation, in fact, is similar to HTML, but looked uncomfortable, changed

Open App.js

// View engine Setupapp.set(' views ', ' views ') ) ); app. Set ('view engine'Jade');

Then replace this code with a

App.set('views '); App.engine ( ' HTML ' , ejs.__express); app. Set ('view engine'html');

Then change the name of the Jade suffix in the view to HTML.

Then install the Ejs module in the project directory

CNPM Install--save Ejs

Then enter NPM start to start the project

Of course it is best to install supervisor so that you do not need to restart the project every time the project has changed, install the Supervisor dependencies First, note that the global

CNPM Install Supervisor-g

Then open the Package.json and find

"Scripts": {    "start": "Node./bin/www"  },

Replace node with supervisor, which is the

" Scripts " : {    "start""supervisor./bin/www"   },

So you don't need to modify the project to restart the project

Configure the Express framework in node. js

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.