npm is used to manage server-side dependencies, but it can be a great tool for managing front-end code too!
If you want to reuse code,
When people want to "share the same code between the browser and the server" they typically have some narrow goal in mind of
This use-case is not very common but is easy to explain.
it's more about
the freedom to move code
use the same modules everywhere
It's not strictly sufficient to
There are many ways to use npm and node-style modules to manage your frontend and backend code without resorting to
check node_modules into git
npm is really great for managing
One thing to watch out for when using node modules is how conflicting versions
each get their own copy of the module matching the version in their package.json
The duplication approach taken by npm solves the incompatible versioning among packages, but can sometimes inflate bundle sizes.
Under normal circumstances on a fresh install, npm will automatically factor out
common dependencies into the most common
node_modules/ directory, but
npm install commands may introduce duplicates.
In these cases,
npm dedupe is your friend!
You can also use
browserify --list main.js to show all the files being
included in your browserify bundle to make sure there are no extraneous
It's important to note that the behavior of npm is fundamentally a feature to ensure the correctness of your programs when dependencies are in conflict. A correct program with more bytes is preferrable to a program with fewer bytes that doesn't work.