I'm learning node and am trying to run a sample app I've pulled from git:
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 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?
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?
Share Improve this question asked Dec 21, 2014 at 0:48 Adam BronfinAdam Bronfin 1,2793 gold badges28 silver badges45 bronze badges5 Answers
Reset to default 5I 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'
I had a similar error.
The problem: I created the config
folder in a sub folder within the root directory.
The solution: Moved the config
folder to the root directory.
Another possible cause of the error could be due to the absence of the configuration files (e.g. config/default.json
, config/production.json
, etc.) in the config folder.
Deleting the config folder that was in my node_modules folder fixed the problem.
Thats because config must be loaded relatively. The require('config')
statement tries to find a module named config in your node_modules directory, where as config here is in the config directory of your root folder. Try changing require('config')
to require('../../config')
. That should solve your problem.
In my case forgot to export the config object in the config file (default.js)
module.exports = config