WebStorm started to build (WebStorm your own installation ......)
In the project root directory create a app.js
Start writing app, js
// introduced HTTP module const = the require HTTP ( "HTTP" ); // can use HTTPS module // const = the require HTTPS ( "HTTPS"); var HTTPService = function (App, Port) { // create a service node // If you need a certificate https var HTTPService = http.createServer (App) .listen (Port); // listening service httpService.on ( 'listening' , onListening); // listener function function onListening () { var addr = HTTPService .Address (); var the bind = typeof addr === 'String' ? 'pipe' + addr : 'port ' + addr.port; console.log('Listening on ' + bind); } } // 模块导出 module.exports = httpService;
app.js (here I used to write specifically is created nodeJs services), it also lacks a start .....
It is also a new start, js files in the root directory
// introduced own module const = Start the require ( './ App' ); // introduced express module const = express the require ( 'express' ); // using web development framework express minimalist // specific search official var App = Express (); // you can use this: // app.use // app.post // app.get // app.delete app.use ( function (REQ, RES, Next) { res.writeHead ( 200 is , { "Content_Type": "text / HTML"}); // set the response format res.write ( "Hello NodeJS" ); res.end (); }); // start service start(app, 8020);
Now start the start.js
After startup to see the console:
Visit:
This completes the service to build a simple nodeJs