1. The introduction of http module
var http = require('http');
2. Create a service
var server = http.createServer();
3. Bind request event
server.on ( 'Request', function (REQ, RES) { // req.url address is accessible IF (req.url === '/ Login' ) { // req.write () returns the data in the page res.write ( 'Login' ) // after use return data end, or can not return data res.end () }else{ res.write('no login') res.end() } })
4. listening port
server.listen(3000,function(){ console.log ( 'successful launch, through http: // localhost: 3000 to access' ); })
In the browser enter: HTTP: // localhost: 3000 / the Login
Display content on the page
Complete code:
// introduced http module var http = The require ( 'http' ); // create a service createServer () var Server = http.createServer (); // ON binding request event server.on ( 'request', function (REQ, RES) { // req.url address is accessible IF (req.url === '/ Login' ) { // req.write () returns the data in the page res.write ( 'Login' ) // return data after use end, or can not return data res.end () }else{ res.write('no login') res.end() } }) // listening port server.listen (3000, function () { console.log ( 'successful launch, through http: // localhost: 3000 to access' ); })