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