如何获取像Unresponsive脚本这样的消息时,如何基于Nodejs运行项目?

时间:2015-07-18 04:05:19

标签: node.js npm bower bower-install

当运行nodejs项目时,消息如Unresponsive script

我在git-hub上有一个基于 angularjs-rickshaw 的项目。它基于nodejs,bower。 项目:ngyewch/angular-rickshaw
上述项目的演示:DEMO

我想在本地系统上运行上面的项目。我成功安装了所有东西(nodejs,npm,bower)。但是当我输入http://localhost:3000/时,我什么都没得到,我是Nodejs的新手,请帮我解决这个问题。什么是正确的网址?

[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/

如果我运行1。http://localhost:3000/或2. http://localhost:3000/#/home,我会收到以下类型的消息 enter image description here

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()+'/');

1 个答案:

答案 0 :(得分:0)

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

正确的方法是:

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

对于staticFilePath以及其他与路径相关的部分,您应该使用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 + '/');
 });