E
E
eeennyg2018-12-10 18:19:06
Node.js
eeennyg, 2018-12-10 18:19:06

How to connect to a node js server?

Hello! I have the following server code on node.js. How can I make it so that I can access the site, say, from a phone or other PC connected to this network?
var express = require('express');
var app = express();
//var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = process.env.PORT || 3000;
app.get('/', function(req, res){
res.sendFile(__dirname + '/main.html');
});
app.get("/chat", function(req, res){
res.sendFile(__dirname + '/chat.html');
});
app.get('/video', function(req, res){
res.sendFile(__dirname + '/video. html');
});
app.get("/photo", function(req, res){
res.sendFile(__dirname + '/photo.html');
});
app.use(express.static('public'));
app.use(express.static('static'));
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
http.listen(port, function(){
console.log('listening on *:' + port);
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2018-12-10
@EreminD

try in the command line (cmd) write hostname
Get the hostname
On another computer, go to http://{ hostname}:3000

A
Alexander Filippenko, 2018-12-10
@alexfilus

If you know the IP of the computer on the internal network (starts at 192.168), then http://{ip}:3000/ should open. If the router is not blocking anything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question