0

I've seen another question here on SO, but I can't for the life of my figure out why I can't get this to work. In the same directory as my node installation I ran the commands npm install and npm install connect. Then again in the same directory as my node installation I created a server.js file:

var connect = require("connect");
var app = connect.createServer().use(connect.static('../angularjs'));
app.listen(8180);

so when then I'm again in my root node directory I do node server.js to start the server and it starts fine. In the root directory of node I made a folder called angularjs and in that folder I placed an index.html. Whenever I navigate in my browser to localhost:8180/index.html I get the message Cannot GET /index.html. It seems that this should be working, what in the world am I missing here?

2
  • 1
    It sounds like .. is wrong. Commented Jun 3, 2014 at 2:27
  • @SLaks i would tend to agree, but I feel like I've tried every permutation and no luck. Commented Jun 3, 2014 at 2:30

1 Answer 1

2

Be careful about where the directory is. From reading your post it appears that you have a node source directory that contains the angularjs directory, so that's what I created when testing.

On Linux, you can examine the directory and what files are in it with the ls or ls -l (verbose) commands

Works here with connect.static() parameter ./angularjs and does not work with ../angularjs

Test procedure

$ mkdir nodetest
$ cd nodetest
$ mkdir angularjs
$ cat >server.js <<EOF
var connect = require("connect");
var app = connect.createServer().use(connect.static('../angularjs'));
app.listen(8180);
EOF
$ npm install connect
$ emacs ./angularjs/test.html # make a html file to get
$ nodejs ./server.js &
$ wget http://localhost:8180/test.html
# fails 404
$ kill %1 // kill nodejs
$ emacs ./server.js # change ../angularjs to ./angularjs
$ nodejs ./server.js &
$ wget http://localhost:8180/test.html
# works
Sign up to request clarification or add additional context in comments.

2 Comments

blah! thanks, i have never seen this one period notation stuff before. always seen two. thanks!
Good luck. One period and a slash is a subdirectory, two periods and a slash means back up a directory first, like cd .., and then go to that directory.

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.