In this shot, we will learn to create a private npm package that can be published.
If you are using npmrc, switch to an appropriate user profile. On the command line, type the following command:
npmrc <profile-name>
// profile-name refers to the user profile name. Replace it with your profile name.
On the command line, type the following command to create a directory for your created package:
mkdir my-test-package
Navigate to your package’s root directory by typing the command below:
cd my-test-package
If you are using git to manage your package code, run the following commands:
git init
git remote add origin git://git-remote-url
Remember to replace
git-remote-url
with the git remote URL for your package.
Run npm init
in the package root directory and pass the scope to the scope flag.
If the package is scoped within an organization, run the following command and replace my-org
with the name of your organization:
npm init --scope=@my-org
For a user-scoped package, replace my-username
with your username:
npm init --scope=@my-username
Respond to the prompts to generate a package.json file.
Although it is optional, it’s a good practice to create a README
file that explains how to use your package.
Open a text editor of your choice and write the code for your package.
Free Resources