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.

0

4 Answers 4

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).

Sign up to request clarification or add additional context in comments.

2 Comments

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
Holy crap! You saved me so much pain in figuring out what was wrong.
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);

1 Comment

'../angularjs' would be one directory up from server.js and inside the 'angularjs' directory. The test.html file does exist there
0

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

use

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

its worked for me

1 Comment

If you face the "nodejs connect cannot find static" error then refer this link stackoverflow.com/questions/24346161/…
-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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.