Node JS Tutorial

Source: Internet
Author: User

Construction of Node JS project:

To create a standard file structure, you need to download and use the Webstorm software to create a new Node Express project.

Operation of App.js:

(1) Introduce a new module: var School_controller = require ('./controller/school_controller ');

(2) Add a new route: App.use ('/school ', school_controller);

Three ways to get parameters:

(1) Gets the parameter value of the GET request: Req.query, visit: Http://localhost:3000?q=ss
Add the routing method in the Index.js file:

Router.get ('/', function (req, res, next) {

Console.log (' Q ' value is: ', req.query.q);

});

(2) Get the parameter value of the POST request: Req.body, Access: Generally get the value of table only son come over

Router.post ('/', function (req, res, next) {

Console.log (' Q ' value is: ', req.body.userName);

});

(3) Get URL path: req.params, visit: http://localhost:3000/ss

Router.get ('/:urlname ', function (req, res,next) {

Console.log (' url Parameter object: ', req.params.urlname);

});

Node JS Tutorial

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.