0

I'm trying to begin the backend of a MEAN project I'm working in right now. It's a project for testing purposes, and Node is still in my TO-DO list.

So, I today wrote this simple server to have something to begin with, and at least being able to see my Angular page and begin to create a simple server-side API. The example can be seen in many websites:

//Lets require/import the HTTP module var http = require('http'); //Lets define a port we want to listen to const PORT=8080; //We need a function which handles requests and send response function handleRequest(request, response){ response.end('It Works!! Path Hit: ' + request.url); } //Create a server var server = http.createServer(handleRequest); //Lets start our server server.listen(PORT, function(){ //Callback triggered when server is successfully listening. Hurray! console.log("Server listening on: http://localhost:%s", PORT); }); 

Well, the problem is quite simple: when I try to access to localhost/myproject, it just doesn't work. Happens the same for 127.0.0.1/myproject. The js file is in the same folder than the project folder, so I should be able to access this way if the server were working.

I looked for an already answered question and found one in which you have to deactivate a directive in Windows Firewall... but that directive doesn't exist in mine.

So, any help with this?

3
  • Can you describe in more detail what does not work, what error messages you get. Commented Feb 26, 2016 at 8:14
  • @Zerok try hitting localhost:8080/myproject Commented Feb 26, 2016 at 8:19
  • I'm not getting any message errors. The page just doesn't load. Commented Feb 26, 2016 at 8:19

1 Answer 1

3

Please add port 8080 to your access url 127.0.0.1:8080/myproject.

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

5 Comments

Hey, now it works! How can I modify my server so I can access to my project folder? Now it just shows the path I'm willing to access.
@Zerok, what do mean access to my project folder?
if I write for example: localhost:8080/myproject, I get a message saying "It Works!! Path Hit: /myproject", instead of actually accessing to the page.
@Zerok, Wow, in your response function function handleRequest(request, response){ response.end('It Works!! Path Hit: ' + request.url); }, there is no render page to response in it. I think maybe you should read some sample projects of MEAN for more details.
Can you please explain what this means to add a port to your access url?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.