NPM Packages

Dong Xia
2 min readAug 26, 2023

NPM — Node Package Manager

The registry for all available npm packages and for the public use https://www.npmjs.com/

A module is a file that has a bunch of export codes. A package is a collection of modules that is reusable and ready to be shared with other developers.

To create a new package run

npm init -y

By adding the -y flag, it will run with the default value. Without the flag, edit the value as see fit.

Once the package.json file has been created. The project is allow to add other additional npm packages into this newly created package by running

npm i <package-name>

These are core packages needed for the current package to work.

npm i <package-name> -D

By adding the -D flag, will add it to devDependencies in the package.json file. Not core, but helpful to the developers in the development process.

This example package, can only do simple addition of 2 numbers. To those who use this package, will only access the sum function that was exported.

Once everything looks great and ready to share. Create an account on https://www.npmjs.com/ and register the package.

--

--