express 的IP绑定时怎么绑的啊? 好像只看到
var app = express();
http.createServer(app).listen(app.get('port'),function(){
console.log('listening ....');
});
原生的如下:
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('hello world');
}).listen(1337,'127.0.0.1');
2 回复
如果原生代码是这个
http.createServer(function(req,res){
res.writeHead(200,{'Content-Type':'text/plain'});
res.end('hello world');
}).listen(1337,'127.0.0.1');
那么用express
可以这么写
var app = express();
http.createServer(app).listen('1337','127.0.0.1');
app.get('/', function(req, res){
res.set('Content-Type', 'text/plain');
res.send('hello world');
});