【发布时间】:2018-02-11 18:26:45
【问题描述】:
我是 Node JS 的新手。我在我的第一个应用程序上遇到了这个问题。节点服务器正在运行。但在控制台中显示端口未定义,而在浏览器中显示拒绝连接。
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req,res) =>{
res.statusCode = 200;
res.setHeader('Content-type','text/plain');
res.end('Hello world');
});
server.listen((port,hostname) => {
console.log('server started on port: '+port);
});
我试过http://127.0.0.1:3000/ 和http://localhost:3000/。但是没用。
【问题讨论】: