我不知道该怎么解决
rm -rf package-lock.json node_modules <-- you need both
npm install
这是我的package.json
{
"name": "xxxx",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "supervisor -i node_modules index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.0",
"bot-brother": "^2.1.5",
"chalk": "^2.4.1",
"cors": "^2.8.4",
"date-fns": "^1.29.0",
"dotenv": "^4.0.0",
"express": "^4.15.4",
"helmet": "^3.8.1",
"joi": "^10.6.0",
"morgan": "^1.9.1",
"pg": "^7.6.1",
"raven": "^2.2.1",
"supervisor": "^0.12.0"
}
}
当我尝试npm start
时收到此错误
我单独安装的唯一软件包是超级用户(npm install超级用户),但这仅仅是因为脚本npm start需要它。
如果您需要其他文件,我很乐意将其发布:)
我不知道该怎么办,我该如何解决?
更新
根据要求,这是bot.js
const bb = require('bot-brother');
const fs = require("fs");
const path = require('path');
const basename = path.basename(__filename);
const bot = bb({
key: process.env.BOT_KEY,
sessionManager: bb.sessionManager.redis({ port: process.env.REDIS_PORT, host: process.env.REDIS_HOST }),
polling: { interval: 5, timeout: 65 }
});
//middlewares
bot.use('before', bb.middlewares.typing());
const actions = {}
//load all actions wrappers
fs
.readdirSync(__dirname + "/actions")
.filter(file => {
return (file.indexOf('.') !== 0) && (file !== basename) && (file.slice(-3) === '.js');
})
.forEach(file => {
const name = file.replace(".js", "")
actions[name] = require(path.join(__dirname + "/actions", file));
});
//load all actions
Object.keys(actions).forEach(name => actions[name](bot))
module.exports = bot
答案 0 :(得分:1)
我看不到任何地方声明了process.env.BOT_KEY
。因此,Key
基本上是未定义的。
要设置BOT_KEY
环境变量,您应该以
BOT_KEY='something' node <filename>
// or
export the BOT_KEY
// or
use `dotenv` and set the config in the config file.
要处理此案件,请通过以下方式处理
:const bot = bb({
....
key: process.env.BOT_KEY || "some secret key",
....
});