Node / connect issue Object function createServer has no method static [duplicate]
Asked Answered
J

1

4

I'm trying to launch my node server using an example from an AngularJS book (server.js).

var connect = require('connect');
connect.createServer(
connect.static("../angularjs")
).listen(5000);

Initially I was getting "object has no method static" so I re-installed the connect include and now when I do: node server.js I get a blinking cursor in CMD (Windows) and "Cannot GET /" from my browser.

Any ideas folks?

Thanks!

Jonathanjonathon answered 1/6, 2014 at 10:8 Comment(5)
Hi, I found that article and used the suggested code - I still get "Cannot GET /"Jonathanjonathon
I think you are reading the same book as me. The connect module has been reorganized. do npm install connect and also npm install serve-static. Afterward your server.js can be written as: var connect = require('connect'); var serveStatic = require('serve-static'); var app = connect(); app.use(serveStatic('../angularjs')); app.listen(5000);Nighttime
@Nighttime this works for me thanks! and yes, we are reading same book :)Mohl
Reading the same book. Adding it to the ERRATA for the book on ApressUnconnected
The issue I had with this was that when entering localhost:PORTNUM in my browser, I had to follow this with the name of the file, e.g. localhost:8000/test.html. Otherwise, yes, the default file it looks for is index.html, in our case for this book, in the /angularjs folderSe
R
5

Your application is working just fine. You just need to specify the name of the file you want to access from static folder in the URL. For example if you have a file called app.html you need to access it via:

http://localhost:5000/app.html

Note that if you just use root URL, it will cause connect to look for default file name, which defaults to index.html. You can change that by passing new default file name in options:

connect.static("../angularjs", {default: "app.html"});
Retainer answered 1/6, 2014 at 10:14 Comment(2)
Weird, I was getting the same "cannot get" error until I put the server.js file into the angularjs folder itself - then it all worked! It's like it can't drill down in to angularjs folder for some reasonJonathanjonathon
As of [email protected], the static middleware has been moved into a separate module. See the update to #28831402Spandrel

© 2022 - 2024 — McMap. All rights reserved.