1

So have read these 2 similar questions

Immediately after the first (and only) Socket.IO connection my Node.js server application quits. But not every time, it seems to happen randomly which makes it more difficult to troubleshoot.

Have Node v 10.16.3 installed in Windows 10.

Can any Node.js experts suggest some troubleshooting steps?

This is the relevant portion of my Node Server app

var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
const os = require('os');

var exec = require('exec');
var child_process = require('child_process');

console.log(os.release());


var options = {
    auth: {
        api_key: 'my key here'
    }
}
var mailer = nodemailer.createTransport(sgTransport(options));


//socket.IO code

var port = 3000;
var sys = require('util');
var express = require('express');


var app = express();

app
    .use(express.static(__dirname + '/public'))
    .get('/', function (req, res) {
        res.write('API');
        res.send('Hello World');
    });

var server = app.listen(port);
var io = require('socket.io');

var sockIO = io.listen(server);

//sockIO.set('heartbeats',false);
//sockIO.set('heartbeat timeout', 1280);

sockIO.sockets.on('connection', function (socket) {
    // new client is here!
    console.log('YES SERVER IS RUNNING and  __dirname is' + __dirname);
    var APP = this;

For package dependencies

 "dependencies": {
    "exec": "^0.2.1",
    "express": "^4.16.2",
    "nodemailer": "^2.7.2",
    "nodemailer-sendgrid-transport": "^0.2.0",
    "sendgrid": "^4.10.0",
    "socket.io": "^1.7.4"
  }   
Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • Are there any errors before the app crashes? The default behavior may be to end the process on unhandled errors, you should attach some error handlers to your server. – Jake Holzinger Sep 17 '19 at 16:42

1 Answers1

0

Answer here Socket.io 1.x: use WebSockets only?

Basically I disabled polling from the client and only allow websocket as transport.

Bachalo
  • 6,965
  • 27
  • 95
  • 189