Anup
Anup

Reputation: 9738

Error - Cannot find module 'config'

I have mail configuration code in all.js.

Now i am trying to import this in my mail.js service, so i imported the config module as follows :-

mail.js

config = require('config'),

all.js

mailer: {
        auth: {
            user: "XXXXXXX",
            pass: "abc@123"
        }
    }

enter image description here

Gives me error cannot find module, but the module exists i have checked it.

How to solve this?

Upvotes: 8

Views: 77461

Answers (3)

codmitu
codmitu

Reputation: 709

so you have to modify the path relative to the file you are using process.env not relative to the specified file config.json

eg:

node_modules
.gitignore
.env
config.json
folder:
     file.js

using config.json in file.js process.env.SECRET_KEY

.env: SECRET_KEY=../config.json //because you go out of folder in file.js to get into config.json

Upvotes: 0

ebentil
ebentil

Reputation: 404

This also occurs when you don't have the config package installed. You may just need to install the config package

npm i config

Upvotes: 4

Anup
Anup

Reputation: 9738

I used the following code & it worked :-

config = require('../config/config');

Upvotes: 13

Related Questions