Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm error ELIFECYCLE on ctrl+c

I've started a new socket.io project with heroku. The server runs fine locally on windows. I start it with npm start but when I shut it down with ctrl + c I get this error in the console:

npm ERR! Windows_NT 6.3.9600
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\
node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v6.11.4
npm ERR! npm  v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the [email protected] start script 'node index.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the test1 package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node index.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs test1
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls test1
npm ERR! There is likely additional logging output above.

I have searched for a solution but the very little I have been able to find has given no solution. I've tried updating npm and node, running npm install again, clearing the npm cache and probably some other actions I can't recall.

Here is my index.js

const express = require('express');
const socketIO = require('socket.io');
const path = require('path');

const PORT = process.env.PORT || 3000;

const server = express()
  .use(express.static(__dirname + '/client'))
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));

const io = socketIO(server);

const pg = require('pg');
var connectionString = "postgres://jdirjtnfueksiw:823e80fbae9599f0d6797f82342d83bccf1caea764b8a1659356f3ee89r69f94@ec1-78-222-138-451.compute-1.amazonaws.com:5432/jf84jd75jgu26d5?ssl=true";

pg.connect(connectionString, function(err, client, done) {
    if (err) {
        throw err;
    }
    else {
        console.log('Database connection test successful');
    }
});

io.on('connection', function (socket) {
        socket.emit('connected');

        console.log('New connection from ' + socket.request.connection.remoteAddress);

        socket.on('disconnect', function () {
            console.log('Player left');
        });
    });

my package.json

{
  "name": "test1",
  "version": "1.0.0",
  "engines": {
    "node": "6.11.4"
  },
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "pg": "6.x",
    "express": "4.13.4",
    "socket.io": "1.4.6"
  },
  "devDependencies": {},
  "description": ""
}

Thank you for any help.

like image 632
Exhy Avatar asked Oct 18 '17 15:10

Exhy


1 Answers

In the index.js can you try putting the following code:

process.on('SIGINT', () => {
    process.exit();
});

I think the issue is that Ctrl+C kills the application but there is still some process running in the background. This will ensure that it is terminated.

Hope this helps!

like image 63
Svetoslav Petrov Avatar answered Oct 01 '22 13:10

Svetoslav Petrov