Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js NODE_PATH environment variable

During development I used to WebStorm node_path =. environment variable. I have set up a variable in the launch of the project settings. Now I want to try to run the project on the server, but do not know how to set this variable there. Help solve the problem!

like image 658
mazorati Avatar asked Nov 25 '13 05:11

mazorati


People also ask

What is Node_path used for?

Use NODE_PATHWhen you end up with a quite complex project structure, requiring modules may get messy. To solve this problem you have two options: symlinking your modules into the node_modules folder. use NODE_PATH.

How do we return a path string from the given path object in node JS?

format() method returns a path string from an object. This is the opposite of path. parse() .

Where is node JS path in Windows?

By default, the installer uses the Node. js distribution in C:\Program Files\nodejs. The installer should set the C:\Program Files\nodejs\bin directory in window's PATH environment variable.


2 Answers

Assuming it's a UNIX or Mac OS X server, use export NODE_PATH= and append the path you want.

like image 121
Tom Grant Avatar answered Sep 20 '22 12:09

Tom Grant


I would recommend setting the variable right before you run the command like so:

NODE_PATH=src/ node myapp.js

This way the variable is set when needed. This is preferable unless you really need to change the path with different versions of your deployment.

If on windows, you can use this lil package to get the effect to work so it is consistent across dev and prod: win-node-env

For bonus points add it to your start script in package.json like so:

"scripts": {
    "start": "NODE_PATH=src/ node myapp.js"
}

Then in production all you need to do is run: npm start

like image 35
mr haven Avatar answered Sep 21 '22 12:09

mr haven