I have a server that won't start correctly on openshift. This is my code:
var connect = require("connect");
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
var httpServer = connect.createServer(connect.static(__dirname + "/public")).listen(port);
console.log("Listening on " + port + "...");
I keep getting this error:
info: socket.io started
warn: error raised: Error: listen EACCES
DEBUG: Program node server.js exited with code 0
DEBUG: Starting child process with 'node server.js'
Listening on 8080...
How can I solve this?
You need to bind the listening IP address to process.env.OPENSHIFT_NODEJS_IP. Here is the example from my working code (I'm using Express) on OpenShift.
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
app.listen(port, ipaddress, function() {
// Do your stuff
});
We need to specify the binding to your OPENSHIFT_NODEJS_IP in your listen like:
var ipaddress = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1"; (do not forget quotes)
var port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
Related
The code shown below fails on Heroku with the error Stopping process with SIGKILL
http.createServer((req, res) => {
var server_port = process.env.YOUR_PORT || process.env.PORT || 80;
var server_host = process.env.YOUR_HOST || '0.0.0.0';
server.listen(server_port, server_host, function() {
console.log('Listening on port %d', server_port);
});
});
Logs:
heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
How can I fix this issue?
You have not declared the variable server.
You can do:
var server = http.createServer((req, res) => {
//your stuff
});
server.listen(process.env.PORT || 80, () => {
console.log("Listening on port 80");
});
I wrote a simple node express server for webRTC using peerjs-server and simple client using peerjs. Everything works fine on localhost, but when I try it on vps, I get error:
Firefox can't connect with server ws://my.vps/peerjs/peerjs?key=peerjs&id=hj3hpekwaa38fr00&token=ymtfvhagiw
PeerJS: Socket closed.
PeerJS: ERROR Error: Lost connection to server.
Error: "Lost connection to server."
emitError https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:16426
_initializeServerConnection https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:12260
emit https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:25516
onclose https://cdnjs.cloudflare.com/ajax/libs/peerjs/0.3.16/peer.min.js:1:19350
Server:
const express = require('express');
enter code here`const app = express();
const ExpressPeerServer = require('peer').ExpressPeerServer;
app.use(express.static('./public'));
const server = app.listen(80, () => { // 3000 on localhost
console.log('Express server listen on port ' + 80);
});
const options = { debug: true };
const peerserver = ExpressPeerServer(server, options);
app.use('/peerjs', peerserver);
app.use('/*', express.static('./public/index.html'));
Client:
var peer = new Peer('', {
host: location.hostname,
port: location.port || (location.protocol === 'https:' ? 443 : 80),
path: '/peerjs',
debug: 3
});
peer.on('open', function (id) {
console.log(id);
});
Any help appreciate.
It looks like you are connecting with server ws://my.vps/, which is a web socket to a server at http://my.vps/ which doesn't seem to exist.
It should probably also be using https (or wss)
Is it possible to connect a udp socket to an external ip after port forwarding is done?
var PORT = 33333;
var HOST = 'xxx.xx.xxx.xxx'; // my external ip
var dgram = require('dgram');
var server = dgram.createSocket('udp4');
server.on('listening', function () {
var address = server.address();
console.log('UDP Server listening on ' + address.address + ":" +
address.port);
});
server.on('message', function (message, remote) {
console.log(remote.address + ':' + remote.port +' - ' +
message);
});
server.bind(PORT, HOST);
port forwarding already set up (below)
I'm getting 'EADDRNOTAVAIL' error
Error: bind EADDRNOTAVAIL xxx.xx.xxx.xxx:33333
Is this even possible? and if not, what are my options for listening in to remote ip addresses?
Thank
Asaf
You can't bind to a non-local address, and you don't need to. Just bind to 0.0.0.0. The port forwarding will do the rest.
Could you use var HOST = '0.0.0.0'; for connecting outside your host?
How can i find the server port number ?
I have following code in server
var app = require('express')();
//creating http server
var server = require('http').createServer(app);
var port = process.env.PORT;
server.listen(port);
app.get('/testUrl', function (req, res) {
console.log(server.address());
console.log(server.address().address);
console.log(server.address().port);
res.end("working " + port);
});
I want to know the port number where node server is running (added consoles in request) I am getting following information using consoles at request
\.\pipe\5e2xxxxxxxxxxxxxxxxxxxxxxxx
undefined
undefined
Server returns following error If I change the server listening port to any other port except process.env.PORT
iisnode encountered an error when processing the request.
HRESULT: 0x2
HTTP status: 500
HTTP subStatus: 1001
HTTP reason: Internal Server Error
The issue in code , your are not defining default port.for set your default port you have to do like this.
var port = process.env.PORT || '';//put your default port here in ''.
and set your PORT in env
export PORT="your port number"(in terminal)
How can I get https server address and port with expressjs?
With http:
var server = app.listen(3000, "127.0.0.1", function () {
var host = server.address().address;
var port = server.address().port;
console.log(server.address());
console.log('Example app listening at http://%s:%s', host, port);
});
result:
{ address: '127.0.0.1', family: 'IPv4', port: 3000 } Example app
listening at http://127.0.0.1:3000
But with https:
https.createServer(options, app).listen(3000, "127.0.0.1", function () {
console.log('Started!');
var host = https.address;
var port = https.port;
console.log('Example app listening at http://%s:%s', host, port);
});
result:
Example app listening at http://undefined:undefined
Any ideas?
may be this link is helpful to you
https://docs.nodejitsu.com/articles/HTTP/servers/how-to-create-a-HTTPS-server/