CNode

express 的 IP 绑定

Xxianggp发布于13 年前最后回复13 年前2 回复14053 浏览0 收藏

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#1·13 年前

如果原生代码是这个

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');
});
参与回复
登录后即可参与回复。登录