// ip 地址用来定位计算机 // 端口号用来定位具体的应用程序 // 所有需要联网通信的应用程序都会占用一个端口号
var http = require('http')
var server = http.createServer()
// 2. 监听 request 请求事件,设置请求处理函数 server.on('request', function (req, res) { console.log('收到请求了,请求路径是:' + req.url) console.log('请求我的客户端的地址是:', req.socket.remoteAddress, req.socket.remotePort)
res.end('hello nodejs') })
server.listen(5000, function () { console.log('服务器启动成功,可以访问了。。。') }) 【ip地址和端口号】转载于:https://www.cnblogs.com/lujieting/p/10296048.html