跳到主要内容
CNode

express 的 IP 绑定

社区
Xxianggp发布于 13 年前最后回复 13 年前
2140730

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)

M
meteormatt#113 年前

如果原生代码是这个

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');
});

参与回复

登录后即可参与回复。登录