Efficiently Managing Your npm Environment

For people who consistently deal with numerous node packages or have to switch between different npm configurations, I found these tools/tips extremely helpful that can boost productivity.

1. npmrc

In case you have to manage different .npmrc files for different configs or registries, the npmrc package is a great tool for switching between various npm configuration environments.

Once you install the package through the command:
npm install -g npmrc
You can now switch between different .npmrc files by using:
npmrc [name]

For larger projects that depend on npm packages currently under development, you can easily symlink local packages to the parent project by using npm link so that you can run the parent project with the newest changes. Package linking is done in the following two steps:

  1. Creating a globally-installed symbolic link from prefix/package_name to the current folder

     cd package_name
     npm link
    
  2. Creating a symlink from the parent project's node_modules folder to the global symlink

     cd parent_project
     npm link package_name
    

3. Nifty Options

  • npm install package_name@version
    This helps you install the specific version you want.
  • npm show package_name
    This gives you an overall info about the module, including versions, repositories, dependencies, etc.
  • npm view package_name field
    This is when you need info about a specific field only from the large output that npm show gives you.
  • npm list [package_name]
    This shows what modules and their versions are currently installed. If you provide the package name, it will give you info about that module only. If you don't want all the dependencies to be shown, you can provide an optional --depth=0.
  • npm config ls
    This shows an overview of your current npm configuration, including registries and users.
Open Comments