Site.js connection timeout - javascript

I'm trying to launch site.js script on my page(http://www.erzis.ct8.pl), but it keeps showing me this error.
[2017-01-04 16:42:34.936] [TRACE] [default] - Strange error
[2017-01-04 16:42:34.936] [DEBUG] [default] - { [Error: listen EPERM 0.0.0.0:8080]
code: 'EPERM',
errno: 'EPERM',
syscall: 'listen',
address: '0.0.0.0',
port: 8080 }
Error: listen EPERM 0.0.0.0:8080
at Object.exports._errnoException (util.js:873:11)
at exports._exceptionWithHostPort (util.js:896:20)
at Server._listen2 (net.js:1237:19)
at listen (net.js:1286:10)
at Server.listen (net.js:1382:5)
at Server.listen.Server.attach (/usr/home/erzis/domains/erzis.ct8.pl/public_html/Bot/BOT/node_modules/socket.io/lib/index.js:228:9)
at null._onTimeout (/usr/home/erzis/domains/erzis.ct8.pl/public_html/Bot/BOT/site.js:618:29)
at Timer.listOnTimeout (timers.js:92:15)

Related

Server crashes when making an API call

app.post("/", (req, res) => {
const origin = req.body.origin;
const destination = req.body.destination;
const urlOri = "https://api.openweathermap.org/data/2.5/weather?q=" + origin + "&APPID={mykey}"
https.get(urlOri, function (response) {
console.log(response);
})
});
I have written this code and I am getting this error:
Server started on port 443
events.js:292
throw er; // Unhandled 'error' event
^
Error: connect ETIMEDOUT 178.128.25.248:443
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
Emitted 'error' event on ClientRequest instance at:
at TLSSocket.socketErrorListener (_http_client.js:469:9)
at TLSSocket.emit (events.js:315:20)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '178.128.25.248',
port: 443
}
This same code runs on one of my friend's pc same as expected, what to do?
I have tried to do the same via request and axios module as well and I got the same error.
Sorry guys I was using a proxy server.
I disabled it and now it's working fine

I keep getting an error in my terminal, "error address already in use :::5000"

I'm following a node.js crash course and I get to the part where we are creating a server, but for some reason every time I try to run node index which is my js file name I'm getting the error:
address already in use :::5000
I've looked through similar problems and tried to kill that specific port but nothing seems to work.
if (req.url === '/') {
fs.readFile(
path.join(__dirname, 'public', 'index.html'),
(err, content) => {
if (err) throw err;
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content);
}
);
}
const PORT = process.env.PORT || 5000;
server.listen(PORT, () => console.log(`Server running on port ${PORT}`));
node index
node:events:504
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::5000
at Server.setupListenHandle [as _listen2] (node:net:1330:16)
at listenInCluster (node:net:1378:12)
at Server.listen (node:net:1465:7)
at Object.<anonymous> (/Users/zacdistant/Documents/GUIDES AND TUTORIALS/Node JS Crash Course/index.js:91:8)
at Module._compile (node:internal/modules/cjs/loader:1097:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1151:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1357:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -48,
syscall: 'listen',
address: '::',
port: 5000
}
If you are on a Mac, port 5000 and 7000 are already used by the Control Center with the AirPlay reveicer:
lsof -i :5000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ControlCe 479 **** 26u IPv4 0xa2d0e96b616f779d 0t0 TCP *:commplex-main (LISTEN)
ControlCe 479 **** 27u IPv6 0xa2d0e96693d0bc65 0t0 TCP *:commplex-main (LISTEN)
To solve the issue you have to either change the port you use in your server like const PORT = process.env.PORT || 9000;, or turn off the AirPlay receiver. Also, if you want to check before hand is the port free, run netstat -anv -p tcp.
As #jamomani explained Mac uses port 5000 and 7000 that are used by the Control Center with the AirPlay receiver
To solve the issue you have to either change the port you use in your server like const PORT = process.env.PORT || 9000;, or turn off the AirPlay receiver. Also, if you want to check before hand is the port free, run netstat -anv -p tcp.

node.js express permission error on linux

using arch with admin user account and no sudo on this script:
var express = require('express');
var fs = require('fs');
var app = express();
app.get('/lol', function(req, res) {
res.sendFile('second.html', {root: __dirname })
});
var port = process.env.PORT || 81;
var server = app.listen(port);
i get this error that didnt change when i changed the port or the url to trigger it
it instantly gives me this error after i run the command: node site.js
(the code above is site.js)
node:events:371
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 0.0.0.0:81
at Server.setupListenHandle [as _listen2] (node:net:1302:21)
at listenInCluster (node:net:1367:12)
at Server.listen (node:net:1454:7)
at Function.listen (/home/{name}/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/home/{name}/Documents/web/demo/site.js:10:18)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1346:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '0.0.0.0',
port: 81
}
if i run the script with sudo it works fine but i dont want to run it in sudo
beacuse i have to run it on a server with no sudo. any help?
Using port below 1024 without root permission is common issue. Try port bigger than 1024.

Nodejs Mariadb on PCF timeout not triggering mariadb events

I have a nodejs application on PCF which connects to a mariadb instance. The instance wait_timeout is 600 so after inactivity it will disconnect after 10 minutes.
On my local machine running this application and connecting to a local instance of mariadb on docker (once timeout hits or when i kill the connection) i will get a MySQL Server has gone away then my application will reconnect and give me my database result. It does not crash locally.
When running this on PCF the mariadb error will crash the application or if the exception is caught it will crash and send a Headers already sent error
I believe that once MariaDB kills the connection somehow the mariadb driver in node is not notified that the connection was terminated even though i have event handlers on the connection. So once my application attempts to run the query it fails because the event was not triggered and its trying to run it on a closed connection.
My connection module
// Loading local .env vars
var route_helper = require("./route_helper");
route_helper.loadLocalEnvVars();
var Client = require('mariasql');
var moment = require('moment');
var connection = null;
try{
connection = new Client({
host: process.env.DB_MARIA_HOST,
user: process.env.DB_MARIA_USER,
password: process.env.DB_MARIA_PASS,
db: process.env.DB_MARIA_SCHEMA,
port: parseInt(process.env.DB_MARIA_PORT),
connTimeout: 20,
pingInterval: 1,
compress: true
});
connection.connect(function(err){
if(!err) {
if(process.env.DEBUG == "true"){
console.log("Database is connected");
}
} else {
console.log("Error connecting database " + err.message);
console.log(err);
}
});
connection.on('ready',function(){
if(process.env.DEBUG == "true"){
console.log("Connection ready " + moment().format('MMMM Do YYYY, h:mm:ss a') )
}
});
connection.on('close',function(){
if(process.env.DEBUG == "true"){
console.log("Connection closed " + moment().format('MMMM Do YYYY, h:mm:ss a') )
}
});
connection.on('error',function(err){
if(process.env.DEBUG == "true"){
console.log("Connection timeout... Reconnecting")
console.log(err);
}
if(err.code == 2006 ){
this.connect();
}
//this.connect();
});
}catch(err){
console.log("Maria_db error")
console.log(err)
throw err;
}
module.exports = connection;
Loading Server routers
var routes = require("./routes/application.js").appRouter(server);
var server = server.listen(process.env.PORT, function () {
console.log("Listening on port %s...", server.address().port);
});
My Route
app.get("/applications", function (req, res) {
try{
var applications;
var dbConn = require("../util/db.js");
dbConn.query('SELECT some stuff’, function (error, results) {
if(!error) {
applications = {
"apps": results
}
return res.send(applications);
} else {
return res.send({"status": "error", "message": error.code});
}
});
}catch(err) {
console.log(err)
}
});
MySql has gone away error
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] OUT { Error: MySQL server has gone away
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/mariasql/lib/Client.js:223:12
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at Client.<anonymous> (/home/vcap/app/util/dbHealth.js:14:9)
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at emitOne (events.js:101:20)
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at Client.emit (events.js:191:7)
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at Client._onerror (/home/vcap/app/node_modules/mariasql/lib/Client.js:395:10)
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at Client._processQueue (/home/vcap/app/node_modules/mariasql/lib/Client.js:614:18)
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at /home/vcap/app/node_modules/mariasql/lib/Client.js:223:12
2017-12-20T09:03:55.29-0500 [APP/PROC/WEB/0] ERR at process._tickCallback (internal/process/next_tick.js:104:9)
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! Failed at the myapplication#1.0.0 start script 'node server.js'.
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! not with npm itself.
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! You can get information on how to open an issue for this project with:
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! npm bugs myapplication
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! Or if that isn't available, you can get their info via:
2017-12-20T09:03:55.31-0500 [APP/PROC/WEB/0] ERR npm ERR! npm owner ls myapplication
2017-12-20T09:03:55.33-0500 [APP/PROC/WEB/0] ERR npm ERR! Please include the following file with any support request:
2017-12-20T09:03:55.33-0500 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/.npm/_logs/2017-12-20T14_03_55_316Z-debug.log
Headers already sent error. They also seem to be out of order which is weird. During this test i am sending 3 http requests to 3 different services and getting this error.
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at _combinedTickCallback (internal/process/next_tick.js:131:7)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at Client._processQueue (/home/vcap/app/node_modules/mariasql/lib/Client.js:614:18)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:180:9) code: 2006 }
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR _http_outgoing.js:494
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at validateHeader (_http_outgoing.js:494:11)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at ServerResponse.send (/home/vcap/app/node_modules/express/lib/response.js:158:21)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at Object.cb (/home/vcap/app/routes/application.js:474:29)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at Client._processQueue (/home/vcap/app/node_modules/mariasql/lib/Client.js:614:18)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at _combinedTickCallback (internal/process/next_tick.js:131:7)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:180:9) code: 2006 }
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR throw new Error('Can\'t set headers after they are sent.');
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR Error: Can't set headers after they are sent.
2017-12-27T11:07:46.41-0500 [APP/PROC/WEB/0] OUT Connection timeout... Reconnecting
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/mariasql/lib/Client.js:223:12
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT { Error: MySQL server has gone away
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT { Error: MySQL server has gone away
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at _combinedTickCallback (internal/process/next_tick.js:131:7)
2017-12-27T11:07:46.41-0500 [APP/PROC/WEB/0] OUT Route: /applications
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT { Error: MySQL server has gone away
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at Client._processQueue (/home/vcap/app/node_modules/mariasql/lib/Client.js:614:18)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/mariasql/lib/Client.js:223:12
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at ServerResponse.setHeader (_http_outgoing.js:501:3)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at ServerResponse.header (/home/vcap/app/node_modules/express/lib/response.js:767:10)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at process._tickCallback (internal/process/next_tick.js:180:9) code: 2006 }
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] OUT at /home/vcap/app/node_modules/mariasql/lib/Client.js:223:12
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR ^
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at ServerResponse.send (/home/vcap/app/node_modules/express/lib/response.js:170:12)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at ServerResponse.json (/home/vcap/app/node_modules/express/lib/response.js:267:15)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at cleanupReqs (/home/vcap/app/node_modules/mariasql/lib/Client.js:744:11)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at Client._onclose (/home/vcap/app/node_modules/mariasql/lib/Client.js:574:5)
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR at Client._onerror (/home/vcap/app/node_modules/mariasql/lib/Client.js:396:10)
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! Failed at the myapplication#1.0.0 start script.
2017-12-27T11:07:46.42-0500 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR!
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! myapplication#1.0.0 start: `node server.js`
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! errno 1
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in:
2017-12-27T11:07:46.43-0500 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/.npm/_logs/2017-12-27T16_07_46_432Z-debug.log
edit: This application structure was generated by swagger
I switch from only mariasql npm driver to knex driver. Even though knex dependancies had mariasql: '^0.2.3' it worked right out of the box with no problems.

Heroku Node deployment "internal server error"

I have my app deployed to heroku. Once I go to the user signup page and enter my credentials the site immediately crashes, displaying internal server error in the browser, and giving me this in the heroku logs.
I'm not sure what might be the issue so I don't know which code to give? I don't think it has to do with MySQL but considering it's mentioned in the error report, it might be? Either way here is my connection.js:
const mysql = require('mysql');
let connection;
if (process.env.JAWSDB_URL) {
connection = mysql.createConnection(process.env.JAWSDB_URL);
} else {
connection = mysql.createConnection({
host: 'localhost',
port: 3306,
user: 'root',
password: '',
database: 'trythis_db'
});
};
connection.connect(function(err) {
if (err) {
console.log(err);
} else {
console.log('mysql is connected');
};
});
module.exports = connection;
This is my error code:
2017-12-04T04:58:51.486756+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:3306
2017-12-04T04:58:51.486150+00:00 app[web.1]: POST /signup 302 287.664 ms - 46
2017-12-04T04:58:51.486758+00:00 app[web.1]: at Object._errnoException (util.js:1024:11)
2017-12-04T04:58:51.486758+00:00 app[web.1]: at _exceptionWithHostPort (util.js:1046:20)
2017-12-04T04:58:51.486759+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
2017-12-04T04:58:51.486760+00:00 app[web.1]: --------------------
2017-12-04T04:58:51.486761+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2017-12-04T04:58:51.486762+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:52:23)
2017-12-04T04:58:51.486763+00:00 app[web.1]: at PoolConnection.connect (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Connection.js:130:18)
2017-12-04T04:58:51.486763+00:00 app[web.1]: at Pool.getConnection (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:48:16)
2017-12-04T04:58:51.486764+00:00 app[web.1]: at Pool.query (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:202:8)
2017-12-04T04:58:51.486765+00:00 app[web.1]: at MySQLStore.set (/app/node_modules/express-mysql-session/lib/index.js:192:19)
2017-12-04T04:58:51.486766+00:00 app[web.1]: at Session.save (/app/node_modules/express-session/session/session.js:72:25)
2017-12-04T04:58:51.486766+00:00 app[web.1]: at Session.save (/app/node_modules/express-session/index.js:381:15)
2017-12-04T04:58:51.486767+00:00 app[web.1]: at ServerResponse.end (/app/node_modules/express-session/index.js:330:21)
2017-12-04T04:58:51.486768+00:00 app[web.1]: at ServerResponse.redirect (/app/node_modules/express/lib/response.js:947:10)
2017-12-04T04:58:51.638706+00:00 app[web.1]: Error: connect ECONNREFUSED 127.0.0.1:3306
2017-12-04T04:58:51.638708+00:00 app[web.1]: at Object._errnoException (util.js:1024:11)
2017-12-04T04:58:51.638709+00:00 app[web.1]: at _exceptionWithHostPort (util.js:1046:20)
2017-12-04T04:58:51.638710+00:00 app[web.1]: at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
2017-12-04T04:58:51.638710+00:00 app[web.1]: --------------------
2017-12-04T04:58:51.638711+00:00 app[web.1]: at Protocol._enqueue (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:145:48)
2017-12-04T04:58:51.638712+00:00 app[web.1]: at Protocol.handshake (/app/node_modules/express-mysql-session/node_modules/mysql/lib/protocol/Protocol.js:52:23)
2017-12-04T04:58:51.638713+00:00 app[web.1]: at PoolConnection.connect (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Connection.js:130:18)
2017-12-04T04:58:51.638713+00:00 app[web.1]: at Pool.getConnection (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:48:16)
2017-12-04T04:58:51.638714+00:00 app[web.1]: at Pool.query (/app/node_modules/express-mysql-session/node_modules/mysql/lib/Pool.js:202:8)
2017-12-04T04:58:51.638802+00:00 app[web.1]: at session (/app/node_modules/express-session/index.js:460:11)
2017-12-04T04:58:51.638800+00:00 app[web.1]: at MySQLStore.get (/app/node_modules/express-mysql-session/lib/index.js:130:19)
2017-12-04T04:58:51.638803+00:00 app[web.1]: at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
2017-12-04T04:58:51.638804+00:00 app[web.1]: at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
2017-12-04T04:58:51.638804+00:00 app[web.1]: at /app/node_modules/express/lib/router/index.js:284:7
The first line of the error (Error: connect ECONNREFUSED 127.0.0.1:3306) says that the app is trying to connect to localhost even when it is hosted online, where it should try to connect to the online database. You need to figure out what's wrong in the if-else statements, since, the else loop is being executed, which, I guess, is for your local environment.
Make sure you have added JAWSDB_URL under project config variables.
(Heroku project -> settings -> config variables -> reveal variables -> your var)
Issue was with another library related to storing sessions in MySQL...

Categories

Resources