F
F
frontendo2017-08-14 12:52:17
Node.js
frontendo, 2017-08-14 12:52:17

How to properly set file paths in nodejs backend?

How to get rid of this problem
const env = require("../../../../../config/env");
as an option I see something like
const env = require(root + "config/env");
I saw when building the frontend addresses like "@/config/env", is it possible to implement this if I don't use any build systems or a transpiler

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Shashenkov, 2017-08-14
@frontendo

set NODE_PATH=./&&node index.js
set NODE_PATH=./is an indication of a global variable NODE_PATHto search for modules in the project, in addition to node_modules.
node index.jsis the launch of the application. && is a command separator
Alternatively, put it in package.json in the scripts section. For example

...
"scripts": {
  ...
  "dev":"set NODE_PATH=./&&node index.js"
  ...
}

And run with the command
Now specify the path The same must be configured for the IDE, so that later it would be easier for her to write hints and monitor the code const env = require("config/env");

D
dummyman, 2017-08-14
@dummyman

It is immediately obvious that you do not use tests in your development.
It is wrong to prescribe configs in source codes. Learn TDD.
Environment from the system is read automatically into the process.env object.
For everything else, there are some state machines .
How they work well on the fingers chewed in the vidosik .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question