创建第一个nodejs应用
var http = require('http');
http.createServer(function(req,res){
res.writeHead(200,{"Context-Type":"text/plain"});
res.end();
}).listen(8080);
console.log('server is running');
访问8080端口就能连接服务器,或者
var http = require('http');
var server = http.createServer();
server.on('request',function(req,res){
res.writeHead(200,{"Context-Type":"text/plain"});
res.end();
});
server.listen(8080);
事件 events模块
var events = require('events');
var eventEmitter = new events.EventEmitter();
eventEmitter.on(‘eventName’,function);
eventEmitter.emit('eventName');
网友评论