2014-09-02 91 views
1

服务器启动时没有任何错误,但URL被击中,显示没有应用程序正在运行。基本Node.js代码不起作用

网址:link_To_Server

我的代码:

var express= require('express'); 
var app=express(); 

app.get('/', function(req, res, next) { 
    console.log('home'); 
    res.send(200); 
    res.end('getting requests'); 
}); 
console.log('server started'); 
+0

这是您的整个代码?如果是这样,你还没有调用'app.listen(port);' – 2014-09-02 09:22:25

回答

5

你实际上并没有设置服务器监听的端口。更换

console.log('server started'); 

随着

app.listen(3000, function() { 
    console.log('server started'); 
}); 

注意,与上面的例子中,绑定端口是3000。欲了解更多信息,请参阅the API doc

+1

请记住,端口3000不会在Cloud9中工作,并且您需要使用$ PORT。在Node.js中,你可以使用'process.env.PORT'。 'process.env.IP'或使用0.0.0.0。 – lcipriani 2014-09-02 09:52:21

+0

非常感谢。请给我发一封邮件([email protected]),以便我可以亲自与您保持联系。由于我是node.js和angular.js的新学员,能否请您指导我。提前感谢。 – Rajeshwar 2014-09-02 10:29:57