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?
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.
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.
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.
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'
Deleting the config folder that was in my node_modules folder fixed the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With