Managing and distributing packages
Once we understand the idea of require
and exports
, we should start thinking about grouping our logic into building blocks. In the Node.js world, these blocks are called modules (or packages). One of the reasons behind the popularity of Node.js is its package management.
Node.js normally comes with two executables—node
and npm
. NPM is a command-line tool that downloads and uploads Node.js packages. The official site, https://npmjs.org/, acts as a central registry. When we create a package via the npm
command, we store it there so that every other developer may use it.
Creating a module
Every module should live in its own directory, which also contains a metadata file called package.json
. In this file, we have set ...
Get Node.js By Example now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.