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.
Run nodemon to start the server. Whenever the server is running, and accessing the route http://localhost:3000/ , it will output the plain text hello world! . We can use the same server to render HTML elements as the server response instead of sending plain text. Here is a list of some HTML elements.
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).
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With