A
A
amagon2017-06-16 22:02:35
Node.js
amagon, 2017-06-16 22:02:35

node.js segmentation error how to fix?

Good day, I am doing a chat on node.js and socket.io wrote the server code

var options = {
//    'log level': 0
};
var fs = require('fs'),

 express = require('express'),
 app = express(),

    socketio = require('socket.io'),
    config = require('./config');

var serverPort = config.port  || 9876, // Listen port
    secure = config.secure || false; // use HTTPS/SSL

var app = express();
if (secure)
{
    var options = {
        key: fs.readFileSync(config.secure_key),
        cert: fs.readFileSync(config.secure_cert)
    };

    var server = require('https').createServer(options, app);

} else
{
   var server = require('http').createServer(app);
}



server.listen(serverPort, function() {
  var addr = server.address();
  console.log('   app listening on ' + (secure ? 'https://' : 'http://') + addr.address + ':' + addr.port);
});

var io = require('socket.io').listen(server, options);


app.use('/static', express.static(__dirname + '/static'));

app.get('/', function (req, res) {
    res.sendfile(__dirname + '/index.html');
});

io.sockets.on('connection', function (client) {
    client.on('message', function (message) {
        try {
            client.emit('message', message);
            client.broadcast.emit('message', message);
        } catch (e) {
            console.log(e);
            client.disconnect();
        }
    });
});

and config
{
    "port": "9876",
    "secure": true,
    "secure_key" : "/opt/privkey.pem",
    "secure_cert" : "/opt/fullchain.pem"
}

I start and get
info - socket.io started
(node:7513) DeprecationWarning: process.EventEmitter is deprecated. Use require('events') instead.
app listening on https://:::9876
but after I try to connect, for example, through the browser https://site.ru:9876/socket.io/socket.io.js node crashes with a Segmentation fault. Can anyone tell me what is causing the segmentation error?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
amagon, 2017-06-17
@amagon

Reinstalled node.js all errors were gone but chat didn't work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question