gpt4 book ai didi

node.js - ctrl+c 上的 npm 错误 ELIFECYCLE

转载 作者:行者123 更新时间:2023-12-03 12:10:02 29 4
gpt4 key购买 nike

我用 heroku 开始了一个新的 socket.io 项目。服务器在 Windows 上本地运行良好。我用 npm start 启动它,但是当我用 ctrl + c 关闭它时,我在控制台中收到此错误:

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! test1@1.0.0 start: `node index.js`
npm ERR! Exit status 3221225786
npm ERR!
npm ERR! Failed at the test1@1.0.0 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.

我一直在寻找解决方案,但我能找到的很少解决方案没有给出解决方案。我已经尝试更新 npm 和 node,再次运行 npm install,清除 npm 缓存以及可能我不记得的其他一些操作。

这是我的 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');
});
});

我的 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": ""
}

感谢您的任何帮助。

最佳答案

index.js你可以尝试输入以下代码:

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

我认为问题是 Ctrl+C 杀死了应用程序,但仍有一些进程在后台运行。这将确保它被终止。

希望这可以帮助!

关于node.js - ctrl+c 上的 npm 错误 ELIFECYCLE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46813538/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com