Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NodeJS sample app failing to startup, unable to find 'config'?

I'm learning node and am trying to run a sample app I've pulled from git:

https://github.com/madhums/node-express-mongoose-demo

After following all the instructions, when I run

npm start

I get an error that says

> [email protected] start /Users/adam419/Desktop/Programming/JSPractice/node-express-mongoose-demo
> NODE_PATH=./config:./app/controllers NODE_ENV=development ./node_modules/.bin/nodemon server.js

20 Dec 16:45:19 - [nodemon] v1.2.1
20 Dec 16:45:19 - [nodemon] to restart at any time, enter `rs`
20 Dec 16:45:19 - [nodemon] watching: *.*
20 Dec 16:45:19 - [nodemon] starting `node --harmony server.js`
WARNING: No configurations found in configuration directory:
WARNING: /Users/adam419/Desktop/Programming/JSPractice/node-express-mongoose-demo/config
WARNING: See https://www.npmjs.org/package/config for more information.

module.js:340
    throw err;
          ^
Error: Cannot find module 'undefined/config/imager.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/adam419/Desktop/Programming/JSPractice/node-express-mongoose-demo/app/models/article.js:10:20)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
20 Dec 16:45:20 - [nodemon] app crashed - waiting for file changes before starting...

This occcurs after making sure I have mongodb installed and running, making sure I've installed all dependencies including 'config'. In fact in node shell when I run

require('config')

the result is undefined.

Why is this application failing to start?

like image 409
Adam Bronfin Avatar asked Dec 21 '14 00:12

Adam Bronfin


People also ask

How do I start node app?

The usual way to run a Node. js program is to run the globally available node command (once you install Node. js) and pass the name of the file you want to execute. While running the command, make sure you are in the same directory which contains the app.

How do I resolve Cannot find module error using node JS?

To solve the "Cannot find module" error in Node. js, make sure to install the package from the error message if it's a third-party package, e.g. npm i somePackage . If you get the error with a local module, make sure to point the node command to a file that exists.

How do I open node JS in Visual Studio code?

Open the project folder in VS Code. Select Node. js when prompted for the application platform. Select either Yes or No when prompted to include Docker Compose files.


2 Answers

I saw that this can happen when the NODE_CONFIG_DIR environment variable is not set. It tells node-config where to find the config files. By default reads configuration files in the ./config directory for the running process, typically the application root.

The node-config docs suggest setting this env variable either in the CLI or in your config file like so:

process.env["NODE_CONFIG_DIR"] = __dirname;

__dirname is OK if the config file is in the same folder as where your default.EXT and other configuration files are, but you might need to change it to the actual path where those files are.

otherwise, we end up with: "WARNING: No configurations found in configuration directory:<PROJECT_ROOT>/config/config" and, subsequently, an error like: 'Configuration property "some-config-key" is not defined'

like image 102
kip2 Avatar answered Oct 07 '22 02:10

kip2


Deleting the config folder that was in my node_modules folder fixed the problem.

like image 42
Adam Bronfin Avatar answered Oct 07 '22 02:10

Adam Bronfin