8

I am beginning to read Pro AngularJS. In the section to setup the development environment it has me create a angularjs directory and put a test.html file into it. Outside of that folder I installed 'connect' and 'serve-static' for Node.js. I also created a server.js file. The contents are seen below:

var connect = require('connect');
var app = connect().use(connect.static('/angularjs'));
app.listen(5000);

When visiting the following URL http://localhost:5000/test.html all I see is the text "Cannot GET /test.html".

I have looked at this and this question here on SO. None of the solutions were helpful for me.

Community
  • 1
  • 1
nbonbon
  • 1,660
  • 3
  • 18
  • 27

4 Answers4

9

The book didn't really do a good job of describing where to put server.js that I remember. So I had it one folder above the angularjs folder. Therefore, the '..' needed to be removed. I made the mistake of leaving in the '/' which caused my problems. Just as I figured ... a stupid small mistake (hardest to find).

nbonbon
  • 1,660
  • 3
  • 18
  • 27
  • 3
    Seriously it is a mistake in this book. For the past two hours I am also banging my head on this mistake. First there was an issue with static in connect module then this. Anyways thanks for the answer – Devesh Feb 17 '15 at 13:23
  • Holy crap! You saved me so much pain in figuring out what was wrong. – Zee Aug 19 '15 at 02:33
1

First, make sure your ../angularjs folder contains test.html file?

Then, you can try to resolve path

var connect = require('connect');
var path = require('path');
var app = connect().use(connect.static(path.resolve(__dirname, '..', 'angularjs')));
app.listen(5000);
  • '../angularjs' would be one directory up from server.js and inside the 'angularjs' directory. The test.html file does exist there – nbonbon Aug 23 '14 at 00:05
0

instead of var app = connect().use(connect.static('/angularjs'));

use

var app = connect().use(connect.static('./angularjs'));

its worked for me

Sunil Yadav
  • 17
  • 1
  • 6
  • If you face the "nodejs connect cannot find static" error then refer this link http://stackoverflow.com/questions/24346161/nodejs-connect-cannot-find-static – Sunil Yadav Aug 01 '16 at 10:51
-2

Below worked out for me.

var connect=require('connect'),
    serveStatic=require('serve-static');

var path = require('path');
var server=connect();

server.use(serveStatic(path.resolve(__dirname, '..', 'angularjs')));

server.listen(5000);
josliber
  • 43,891
  • 12
  • 98
  • 133