node.js - Setting NODE_PATH from within NodeJS application -


We have a node project, for which our own submodules are not required from any relative path, but instead < Code> NODE_PATH Environment variables can be set to lib to find all the codes

I want to handle this standard case within the program source code But it seems that it is impossible by now.

I have found many solutions that do not work as expected at all.

Module paths.push (". / Lib");

Another Stackworflow article was suggested but it refers to the developer to use an error message in the new node versions and NODE_PATH .

Instead, I tried to do the following as the first line of my program.

process.env ['NODE_PATH'] = "./ lib";

This is not the cause of an error message, but it does not work either. I think this variable is read on starting the app and does not read the lateron when the content is necessary.

You can find all the information from the source:

. .. NODE_PATH error is thrown only when reaching through need.paths .

Search for the _nodeModulePaths function: The module instance has the generic array object path , with all the lookup paths in it.

  module.paths.unshift ('./foo-baz'); Var x = Required ('some-lib-name'); Console.log (x);   

So now, if you have . If there is a module under / Foo-baz / some-lib-name / , then it will be picked properly.

What is the node version and what system do you have?

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -