Running node.js on a port other than port 80

I have an Apache web server running on my ubuntu server. I recently tried to learn JavaScript, and I came across node.js. I would like to create some multiplayer games for web applications, and I found out that node.js can come in handy. I am having problems with the configuration. How will I run both apache and node.js servers on the same computer? I do not mind if the applications on node.js are on a different port and should be accessible by entering the server_name: portNumber in the file. I'm not too concerned about performance advantages / disadvantages, I just want to take the opportunity to try JavaScript and node.js. Are there any files that need to be changed?

Here is the code that I have for the script running on the server (only for its use at the moment):

var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337); 

I started the server (node ​​fileName.js). However, when I try to access it with another client computer on the network, it does not seem to work because the page does not seem to exist.

What is the procedure so that I can get Hello World for my browser when I visit the server on port 1337?

+4
source share
2 answers

Try this as follows:

 http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(1337, "your-adapter-ip"); // don't forget adapter IP 

And then from the network point your browser to http: // your-adapter-ip: 1337 .
Verify that the firewall is open on this port.

+6
source

You should be able to view http://your_ubuntu_server_ip:1337 from another client computer.

Can you connect to the Apache web server from another computer? If so, you can stop apache, change your code to use port 80, and try again.

0
source

Source: https://habr.com/ru/post/1391570/


All Articles