如何运行基于Nodejs的项目,当得到像无响应脚本的消息?

当运行nodejs项目时,消息像Unresponsive脚本

我在基于angularjs-rickshaw的 git-hub上获得了一个项目。 它基于nodejs,bower。 项目: ngyewch /angular人力车
以上项目演示 : DEMO

我想在我的本地系统上面运行项目。 我成功安装了每个东西(nodejs,npm,bower)。 但是,当我inputhttp://localhost:3000/我什么也没有得到,我在Nodejs中是新的, 请帮助我。 什么将是正确的url?

 [neelabh@localhost angular-rickshaw]$ node server.js connect.multipart() will be removed in connect 3.0 visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives connect.limit() will be removed in connect 3.0 Server running at http://localhost:3000/ 

我得到以下types的消息,如果我运行1. http:// localhost:3000 /或2. http:// localhost:3000 /#/ home 在这里输入图像描述

server.js

 'use strict'; var fs =require('fs'); //for image upload file handling var express = require('express'); var app = express(); var port =3000; var host ='localhost'; var serverPath ='/'; var staticPath ='/'; //var staticFilePath = __dirname + serverPath; var path = require('path'); var staticFilePath = path.join(__dirname, serverPath); // remove trailing slash if present if(staticFilePath.substr(-1) === '/'){ staticFilePath = staticFilePath.substr(0, staticFilePath.length - 1); } app.configure(function(){ // compress static content app.use(express.compress()); app.use(serverPath, express.static(staticFilePath)); //serve static files app.use(express.bodyParser()); //for post content / files - not sure if this is actually necessary? }); //catch all route to serve index.html (main frontend app) app.get('*', function(req, res){ res.sendfile(staticFilePath + staticPath+ 'index.html'); }); app.listen(3000, function () { console.log('Server running at http://' + host + ':' + port + '/'); }) //app.listen(port); //console.log('Server running at http://'+host+':'+port.toString()+'/'); 

查看https://github.com/ngyewch/angular-rickshaw/blob/gh-pages/server.js,console.log console.log('Server running at http://'+host+':'+port.toString()+'/')应该是一个callback来listen电话。 否则,即使服务器没有正常启动, console.log也会被执行。

正确的方法是:

  app.listen(3000, function () { console.log('Server running at http://' + host + ':' + port + '/'); }); 

对于staticFilePath和其他path相关的部分,您应该使用path.join

  var path = require('path'); var staticFilePath = path.join(__dirname, serverPath); 

最终,最好将所有静态文件移动到public目录,并使用express.static中间件进行提供:

 'use strict'; var express = require('express'); var app = express(); var port = 3000; app.use(express.static('public')); app.listen(port, function () { console.log('Server running at http://' + host + ':' + port + '/'); });