错误:在Function.Module._resolveFilename上找不到模块config‘


Hii我有一个简单的节点服务器,结构如下

myapp
 -config 
    -default-json
 -index.js
 -package-lock.json
 -package.json

这是我的index.js的一部分

'use strict';

const
    config = require('config'),
    express = require('express'),
    request = require('request'),
    body_parser = require('body-parser'),
    app = express().use(body_parser.json()); // creates express http server

// Sets server port and logs message on success
app.listen(process.env.PORT || 1337, () => console.log('webhook is listening'));

当我运行节点index.js时,我得到以下错误

internal/modules/cjs/loader.js:583
    throw err;
    ^

Error: Cannot find module 'config'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
    at Function.Module._load (internal/modules/cjs/loader.js:507:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (C:\xampp\htdocs\chat\index.js:13:14)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)

我的代码出了什么问题?

转载请注明出处:http://www.cxyjjj.com/article/20230526/1202383.html