2

I'm using the config package in Node.js to organize all my environment variables, and it works perfectly in my local environment. However, when I deploy the app to Vercel, I encounter the following error:

WARNING: NODE_ENV value of 'production' did not match any deployment config file names. WARNING: See https://github.com/node-config/node-config/wiki/Strict-Mode WARNING: No configurations found in configuration directory:/var/task/config WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment. Error: Configuration property "logging.level" is not defined at Config.get (/var/task/server/node_modules/config/lib/config.js:179:11) at Object. (/var/task/server/logger/index.js:5:22) at Module._compile (node:internal/modules/cjs/loader:1256:14) at Module._extensions..js (node:internal/modules/cjs/loader:1310:10) at Module.load (node:internal/modules/cjs/loader:1119:32) at Module._load (node:internal/modules/cjs/loader:960:12) at t..e._load (/var/task/___vc/__launcher/__launcher.js:14:2299) at Module.require (node:internal/modules/cjs/loader:1143:19) at require (node:internal/modules/cjs/helpers:119:18) at Object. (/var/task/server/index.js:8:16) INIT_REPORT Init Duration: 716.96 ms Phase: invoke Status: error Error Type: Runtime.ExitError Error: Runtime exited with error: exit status 1 Runtime.ExitError The configuration files are located in the ./config folder: development.json, production.json, and default.json. Details about the app are provided below:

package.json

{
  "name": "My app",
  "version": "1.0.0",
  "description": "A Application",
  "main": "index.js",
  "engines": {
    "node": "18.x"
  },
  "scripts": {
    "dev": "nodemon index.js",
    "start": "node index.js"
  },
  "author": "hhh",
  "license": "ISC",
  "dependencies": {
    "bcrypt": "^5.1.0",
    "compression": "^1.7.4",
    "config": "^3.3.8",
    "cors": "^2.8.5",
    "crypto-js": "^4.1.1",
    "express": "^4.18.2",
    "express-async-errors": "^3.1.1",
    "handlebars": "^4.7.7",
    "helmet": "^6.0.0",
    "joi": "^17.7.0",
    "jsonwebtoken": "^8.5.1",
    "lodash": "^4.17.21",
    "mongodb": "^5.3.0",
    "mongoose": "^6.7.3",
    "node-schedule": "^2.1.1",
    "nodemailer": "^6.8.0",
    "socket.io": "^4.6.1",
    "uuid": "^9.0.0",
    "winston": "^3.8.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }
}

vercel.json

{
  "version": 2,
  "builds": [
    {
      "src": "./index.js",
      "use": "@vercel/node"
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/"
    }
  ]
}

./config/default.json

{
  "logging": {
    "level": "info",
    "trace": true
  }
}

Now, from the app:

const config = require("config");
const level = config.get("logging.level"); // ERROR

I also tried setting the environment variable NODE_CONFIG_DIR='./config', still not working 😩. Please help me here?

1 Answer 1

0

Add the below two line before using config:

const express = require('express');
process.env['NODE_CONFIG_DIR'] = path.join(path.resolve("./"),"config/")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.