I'd like to run Node.js server in virtual machine.
I executed vagrant up
and node Server.js
.
Then I accessed to http://192.168.33.10:1337/
from host machine browser.
But, the browser outputs ERR_EMPTY_RESPONSE
.
How do I fix it?
Vagrantfile
Vagrant.configure(2) do |config|
config.vm.box = "centos"
config.vm.network "private_network", ip: "192.168.33.10"
end
Server.js
var http = require('http');
http.createServer(function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(1337, "192.168.33.10");
console.log('server running');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.