illdo illdo - 1 year ago 332
Node.js Question

How to set NODE_PATH=. for node.js app hosted in openshift

I use custom node.js cartridge on openshift
icflorescu/openshift-cartridge-nodejs .

How can i set NODE_PATH=. for app start in package.json ? Should i provide it in package.json like that :

"start": "NODE_PATH=. NODE_ENV=production node app.js"
either i should use something like here
Dindaleon/hapi-react-starter-kit - some npm package like

I have line in main app.js file. There is folder named 'config', in the same directory with app.js, in folder config placed file index.js, file index.js have code with 'module.exports = Object.assign({ ...some conifg object... });' . When i delete NODE_PATH=. , node throws "Error: Cannot find module 'config' " .

var config = require('config');

Answer Source

I'm the author of openshift-cartridge-nodejs :-)

Having "start": "node app.js" in your package.json should be just enough.

If you take a look at bin/install, you'll see that NODE_ENV is already set to production by default in the cartridge setup script.

Also, I'm not sure what you're trying to achieve by setting NODE_PATH to .. There's a single Node.js version installed.

If you're generally interested in how you can set custom environment variables in an OpenShift-deployed application, have a look at the docs here. Basically you'll have to use the rhc command-line utility like this:

$ rhc env set <Variable>=<Value> <Variable2>=<Value2> -a App_Name
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download