I created a web server with node.js, but I can't access the web page.

Asked 2 years ago, Updated 2 years ago, 98 views

Thank you for your help.

I created a web server with node.js, but I can't access the web page. (I can't see it in my browser)

Filename server.js

var http=require('http');
var server = http.createServer();
server.on('request', function(req,res){
    res.writeHead(200, {'Content-Type':'text/plain'});
    res.write('hello world');
    res.end();
});

server.listen(1337, '127.0.0.1');
console.log("server listening...");

Terminal View Results

 [vagrant@localhostnodejs]$ node server.js

server listening...

I accessed it with localhost:1337, but the browser (chrome) says I cannot access this web page.

When I did as you advised, the following problem occurred.

[vagrant@localhostnodejs]$curl http://localhost:1337/
curl:(7) couldn't connect to host

It was written that it would be good to do the following to always set the proxy, so I tried it, but it seems that vi recognizes that writing is prohibited.

#vi/etc/bashrc

(I opened it with vi, so I added the following to the last line.)

alias curl="curl-x http://proxy.jpn.hp.com:8080/"

(: Save with wq and exit)

It looks like I'm going to use chmod to change the file, so please tell me how to write it to which file (bashrc?).

Thank you for your cooperation.

node.js

2022-09-30 20:48

1 Answers

It seems to be running in a virtual environment, so it might be a network problem in that environment.
First, try accessing from the same environment as below.

node server.js&
curl http://localhost:1337/


2022-09-30 20:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.