Node.js——基本服务开启

标注模式

var http = require('http');

var server = http.createServer();

server.on('request', function (req, res) {
    res.end('Hello World')
})

server.listen(3000, function () {
    console.log('server is running...')
})

简写模式

var http = require('http');

http.createServer(function (req, res) {
    res.end('Hello World')
}).listen(3000, function () {
    console.log('server is running...')
})

 

posted @ 2018-06-14 19:31  var_obj  阅读(959)  评论(0编辑  收藏  举报