2

When run nodejs project, the message like Unresponsive script

I got one project on git-hub based on angularjs-rickshaw. It is based on nodejs, bower. Project: ngyewch/angular-rickshaw
Demo of above project: DEMO

I want to run above project on my local system. I successfully installed every thing (nodejs, npm, bower). But When I type http://localhost:3000/ I get nothing, I am new in Nodejs, please help me on this. What will be the correct 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/

I am getting following type of message if I ran 1.http://localhost:3000/ or 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()+'/');
geeks
  • 2,025
  • 6
  • 31
  • 49
  • Try `http://localhost:3000/#/home` – brandonscript Jul 18 '15 at 04:29
  • 2
    The project you're referring to is AngularJS. Where is your Node.js code that you added? – krl Jul 18 '15 at 04:34
  • @kyrylkov Thanks for reply, Node.js is installed system-wise, when I run `node --version` I am getting v0.12.7, I think you were asking nodejs is installed or not, Please let me know if anything you were asking.. – geeks Jul 18 '15 at 05:52
  • @remus I tried `http://localhost:3000/#/home` but I am getting the message like Unresponsive script..... – geeks Jul 18 '15 at 05:54
  • @kyrylkov "Where is your Node.js code that you added?" I didn't get your question correctly............. – geeks Jul 18 '15 at 06:03
  • Where `server.js` file comes from? It's not a part of `angularjs-rickshaw`. So where did you get it and what's in it? – krl Jul 18 '15 at 09:14
  • @kyrylkov, Thanks for pointing out. Updated the link, server.js is not available in master_branch in 'gh-pages' https://github.com/ngyewch/angular-rickshaw/tree/gh-pages – geeks Jul 18 '15 at 10:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83616/discussion-between-kyrylkov-and-neelabh-singh). – krl Jul 18 '15 at 13:06

1 Answers1

0

Looking at https://github.com/ngyewch/angular-rickshaw/blob/gh-pages/server.js, console.log('Server running at http://'+host+':'+port.toString()+'/') should be a callback to listen call. Otherwise console.log always gets executed, even if the server doesn't start properly.

The correct way is:

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

For staticFilePath and in other path-related parts you should use path.join:

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

Ultimately it's best to move all static files to public directory and serve it with express.static middleware:

'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 + '/');
 });
krl
  • 5,087
  • 4
  • 36
  • 53
  • Should I modify server.js file according to your code..If Yes where to put path =require('path'); – geeks Jul 18 '15 at 11:52
  • Yes. `var path` should go before `path.join`. – krl Jul 18 '15 at 11:55
  • Please see the updated question I added server.js as you told me to do It is still unresponsive ..... – geeks Jul 18 '15 at 12:00
  • `console.log` executed in callback? You don't need to remove trailing slash manually. `res.sendfile` should also use `path.join`. Even better leave all this verboseness out, put all static files to `public` folder and use `app.use(express.static('public'))` to serve all static files in `public` folder. – krl Jul 18 '15 at 12:19
  • console.log is giving error like `SyntaxError: expected expression, got '<'` – geeks Jul 18 '15 at 12:46
  • using shortest code with `app.use(express.static('public'))`? – krl Jul 18 '15 at 13:05