![](/img/trans.png)
[英]nodemon app crashed (without error) in production, works in localhost
[英]nodemon app crashed - and returning error that ERR MODULE NOT FOUND
我正在尝试为 openAI GPT 运行 nodemon 服务器
这是.json 文件
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "server.js",
"type": "module",
"scripts": {
"server": "nodemon server"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"nodemon": "^2.0.20",
"openai": "^3.1.0"
}
}
这是 server.js 文件
import express from 'express';
import * as dotenv from 'dotenv';
import cors from 'cors';
import { Configuration, OpenAIApi } from 'openai';
dotenv.config();
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const app = express();
app.use((cors()));
app.use(express.json());
app.get('/', async (req, res) => {
res.status(200).send({
message: 'Hello form Codex',
})
});
app.post('/', async (req, res) => {
try {
const prompt = req.body.prompt; //front end
const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: `${prompt}`,
temperature: 0,
max_tokens: 3000,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});
res.status(200).send({
bot: response.data.choices[0].text
})
} catch (error) {
console.log(error);
res.status(500).send({ error })
}
})
app.listen(5000, ()=> console.log('Server is running on port http://localhost:5000'));
这是我的代码,请解决我的服务器在终端中返回错误的问题
code: 'ERR_MODULE_NOT_FOUND'
}
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
我正在尝试使用命令在终端上运行服务器 = npm run server
但它引发错误 ERR_MODULE_NOT_FOUND 和 [nodemon] 应用程序崩溃 - 在开始之前等待文件更改......
我期待运行服务器并且它不会返回任何错误
你没有安装express NPM Package
跑步
npm i express
在项目根目录中的终端中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.