Search code examples
node.jsforever

Issue with running node app using forever


So I have a node.js app in which I am using node-config-manager, to manage the various environments (development, staging, production).

I am trying to use forever to run this process in the background, however when I run forever start /path/to/main.js, it is telling me

Error: No file for this config - app.

The error is saying it's coming from line 9. When it first tries to add a configuration file, app.json.

1.   import configManager from 'node-config-manager';
2.   const options = {
3.     configDir: './config',
4.     env: 'develop',
5.     camelCase: true
6.   };
7.   console.log(process.env.NODE_ENV);
8.   configManager.init(options);
9.   configManager.addConfig('app');
10.  configManager.addConfig('logger');
11.  configManager.addConfig('db');

export default configManager;

Inside my config folder I have three other folders, 'develop', 'staging', and 'production'.

Inside all of these folders I have three files, app.json, db.json, & logger.json.

So I am not sure what is causing the problem here. The config 'develop' does in fact exist, but there seems to be something wrong.

This app runs fine when I start it with nodemon, it's just forever thats causing problems.

Am I missing something with my understanding of how node-config-manager works? I thought all i had to do was change my NODE_ENV variable to the name of the folder inside my config directory and i'd be all set.

Thanks in advance for all the help.


Solution

  • the ./ directive for the config file looks at the relative path from the current working directory. forever is probably not being run from the working directory of the project, so it can't find the file.

    if you project lives in /path/to then you need to provide that as the --workdingDir parameter to forever.

    forever start /path/to/main.js --workingDir=/path/to/

    that should take care of it