zeit-pkg-path
Node 8+
Helps to resolve paths when using pkg (detects if using packaged app or testing via node cli.js) related to current working dir of running app (where the app is installed or where node was executed).
Example
# Running in /root/ node test/cli.js# Path returned via path.resolve('test.png') # > /root/test.png # Running in /root/ node cli.js# Path returned via path.resolve('test.png') # > /root/test.png # Running in /root/test ./cli # Path returned via path.resolve('test.png') # /root/test/test.png
Install
npm install zeit-pkg-path
Usage
// in context /root/testconst path = // Resolves path based on current base pathconsole// /root/index.js console// /root/test/index console// True if running via node index.js, false if running in packaged executable // Replaces base path from given string with dot to make it relativeconsole// ./index.js // Returns the base pathconsole// /root/test