【问题标题】:nodemon app crashed - and returning error that ERR MODULE NOT FOUNDnodemon 应用程序崩溃 - 并返回 ERR MODULE NOT FOUND 错误
【发布时间】:2023-01-08 00:07:48
【问题描述】:

我正在尝试为 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 但它不在您的依赖项中,您确定已安装它吗?

标签: javascript node.js server localhost node-modules


【解决方案1】:

您还没有导入 express NPM 包

跑步

npm i express

在项目根目录中的终端中

【讨论】:

    猜你喜欢
    • 2018-06-22
    • 1970-01-01
    • 2020-06-07
    • 1970-01-01
    • 2021-06-21
    • 2017-09-10
    • 2021-11-27
    • 1970-01-01
    • 2016-07-02
    相关资源
    最近更新 更多