How to use executables from a package installed locally in node_modules?

前端 未结 22 2128
时光说笑
时光说笑 2020-11-22 12:40

How do I use a local version of a module in node.js. For example, in my app, I installed coffee-script:

npm install coffee-script
22条回答
  •  情深已故
    2020-11-22 13:21

    You don't have to manipulate $PATH anymore!

    From npm@5.2.0, npm ships with npx package which lets you run commands from a local node_modules/.bin or from a central cache.

    Simply run:

    $ npx [options] [@version] [command-arg]...
    

    By default, npx will check whether exists in $PATH, or in the local project binaries, and execute that.

    Calling npx when isn't already in your $PATH will automatically install a package with that name from the NPM registry for you, and invoke it. When it's done, the installed package won’t be anywhere in your globals, so you won’t have to worry about pollution in the long-term. You can prevent this behaviour by providing --no-install option.

    For npm < 5.2.0, you can install npx package manually by running the following command:

    $ npm install -g npx
    

提交回复
热议问题