Skip to content

Instantly share code, notes, and snippets.

@dsernst
Last active November 4, 2015 07:58
Show Gist options
  • Save dsernst/7c511c8b444507721428 to your computer and use it in GitHub Desktop.
Save dsernst/7c511c8b444507721428 to your computer and use it in GitHub Desktop.
How to use distinct npm packages across a host & VM when using a shared project folder

How to use distinctly compiled npm packages across a host machine & VM with a shared project folder

Use bcrypt and mongoose in each, with their own, OS-specific bindings
  1. Go to your ~/ home directory on the machine you want to install OS-specific module for, then run $ npm i compiled-package

  2. Move your package into ~/.node_modules folder (this is a special folder node knows to look in when requireing modules)

  • So probably: $ mv ~/node_modules/compiled-package ~/.node_modules/compiled-package
    • Shorthand: $ mv ~/{,.}node_modules/compiled-package
  • (consider rm -rfing the first node_modules folder to clean up after yourself)
  1. Repeat for your other OS

  2. In your project’s directory, remove the package you want distinctly compiled:

  • e.g. rm -rf ~/Documents/my-project/node_modules/compiled-package
  • so that node will fall back to the home directory /node_modules/
  • this lets you keep indepedently compiled packages for each machine

Victory! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment