What I want to understand is what are the main differences between;
<script src="module_url.js"></script>
vs
npm install module
Does one have any performance benefits? Or which one of those is better for separation of concerns? My question is specific to Node.js but answers for other platforms, frameworks, etc. are highly appreciated.
To use any NodeJS module, you have to do npm install <module>
Script includes is basically for client side loading i.e. UI code, as this approach reduces the load on the server (for serving the libraries). Usually libraries are hosted on CDN
servers, which allows faster downloads at that geo-location.
Sometimes, the scripts might not be available as CDN
and/or you might have custom version of the library script, in these cases you will want to use bundlers
like webpack
or browserify
to serve your client libraries from Node backend-for-frontend or an web server.
Bundlers basically allows you to reduce the code size and faster serving. Ref: JS Bundlers