Sourav Chatterjee
Sourav Chatterjee

Reputation: 810

Running node CLI module locally

I am having an node module which is a CLI script. The CLI uses the process.cwd() to get the current directory from which the cli script is invoked( that is important). This works fine when I install the CLI module globally (https://www.npmjs.com/package/reduxboilergen)

npm i -g <module>

But when I install it locally npm i -S <module> Then 1) The script is not invoked 2) I added a script in package.json and then if I run npm run "script_name", it is invoked but it always takes the directory from where the npm script is invoked as the process.cwd(). So if the folder structure is root - src Then even if I run it inside src directory its picking up root as cwd() as the package.json is in root.

The node_module npm-run ( https://github.com/timoxley/npm-run) solves this problem but is there any other way that you experts can think of so that I dont have to add this dependency?

Upvotes: 0

Views: 84

Answers (1)

Sourav Chatterjee
Sourav Chatterjee

Reputation: 810

The answer would be npx as of npm 5.2.0

Upvotes: -1

Related Questions