Friday, 28 April 2017

Requiring path from an executable location

How can I get a relative path to the executable location in node?

Using webpack, I have the following directory structure:

dist
  executable.js
  config.js
src
  controllers
    script.js
  index.js

I want to require config.js file from the script.js file. The path can be changed, the location of script.js also might change in the future, so I need a way to automatically get the relative path to /dist from anywhere inside src folder - is this possible?

I am using webpack to build the output file. Executable is called by:

node dist/executable.js



via user99999

No comments:

Post a Comment