A
A
Al2016-06-15 12:37:04
cmd/bat
Al, 2016-06-15 12:37:04

Why can't node.js find plugins when run from bat file?

There is a batch file:

set NODE_PATH="."
set NODE_ENV="development"
node --use_strict  C:\Users\uuui\js\bin\server.js
PAUSE

Everything seems to be working, the variables in process.env are set correctly, but at startup I get an error: Error: Cannot find module
As if the node itself is changing something. But through webstorm everything works fine.
UPD:
After digging, I realized that the problem is that all the paths passed to require are not relative, so the node looks for modules in the wrong place. But how to be now? Edit all paths using the path module , or make them relative? There will also be a problem with specifying folders inside scripts (for example, downloading files, etc.), i.e. for them, it will also be necessary to redo the paths to relative ones.
Is there a more simplified way out of the situation? WebStorm somehow copes with this...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
res2001, 2016-06-15
@res2001

I think that the node sees the variables, most likely it changes the current directory and "." already looking somewhere else. Write the full path to NODE_PATH.

V
Vladimir Kuzin, 2016-06-15
@Bobson8

You can add a module with js to the system environment variable. Then it should work without unnecessary paths and errors.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question