Reputation: 959
I am working on a Node.js app.
Hosting of node js for my app is not working so I just create one small sample demo for hosting node js on server but still its not working.
I share you the code and step that I have done until now for setup the code.
ServerDemo.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(12043, '0.0.0.0');
console.log('Server running at : http://0.0.0.0:12043/');
then I have connect my server from PuTTy and then I run my serverdemo.js
with following command
nodejs /var/www/websites/webrtc.windinternet.nl/htdocs/webrtcapp/serverdemo.js
it will so the following output
Server running at : http://0.0.0.0:12043/
then I enter
$ netstat -an | grep "LISTEN "
which so following output
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:12043 0.0.0.0:* LISTEN
tcp6 0 0 :::4949 :::* LISTEN
tcp6 0 0 :::21 :::* LISTEN
tcp6 0 0 ::1:25 :::* LISTEN
tcp6 0 0 :::80 :::* LISTEN
so port 12043 is listening but when I'm running $ nmap -sT localhost
command it shows only following ports are open:
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
25/tcp open smtp
80/tcp open http
3306/tcp open mysql
when I am trying to access http://test.domain.com:12043
it always display The webpage is not available
.
If you need any more description from my side, please add comments.
Upvotes: 2
Views: 1715
Reputation: 1
The code below will work. Try it once...
Give your machine an IP address or localhost
instead of 0.0.0.0
.
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(12043, 'localhost');
console.log('Server running at : http://localhost:12043/');
Upvotes: 0
Reputation: 959
While you host Node.js application on shared server as per my question you have to run follow above steps as i mention and at last you need to open respected port on server for running node.js application.
Command : telnet -l username test.domain.com 12043
This telnet command open the respected port and Your application is working fine.
Upvotes: 1