Step-by-Step Guide: Create a Node.js Project with npm and Upload Artifacts to Artifactory
1. Install Prerequisites
- Node.js and npm: Download and install Node.js, which includes npm. Check installation with: text
node -v npm -v
2. Initialize a New Node.js Project
- Create a new directory for your project and navigate into it: text
mkdir my-node-project cd my-node-project
- Initialize a Node.js project with: text
npm init
Answer the prompts (project name, version, etc.) or usenpm init -y
to accept the defaults and generatepackage.json
12345.
3. Develop Your Node.js Artifact
- Add your source files. Commonly, you’ll have an
index.js
ormain.js
, and add dependencies as needed: textnpm install <dependency>
4. Configure Artifactory for npm Publish
a. Obtain Artifactory Information
- You need:
- Your Artifactory npm repository URL (e.g.,
https://company.jfrog.io/artifactory/api/npm/npm-local/
) - Your Artifactory username and API key or password
- Your Artifactory npm repository URL (e.g.,
b. Set the Registry in Your Project
- Add the
publishConfig
block to yourpackage.json
to specify the Artifactory registry: json"publishConfig": { "registry": "https://company.jfrog.io/artifactory/api/npm/npm-local/" }
Replace the URL with your actual Artifactory repository URL678.
c. Authenticate npm with Artifactory
- To authenticate, run in your terminal (replace the URL with your Artifactory npm repository): text
npm login --registry=https://company.jfrog.io/artifactory/api/npm/npm-local/
Enter your Artifactory credentials. This creates or updates the.npmrc
file with authentication tokens for your registry67.
5. Publish Your Artifact to Artifactory
- Once you’re ready to upload: text
npm publish
This command will upload your package based on the configuration inpublishConfig
. Alternatively, you can override the registry in the publish command: textnpm publish --registry=https://company.jfrog.io/artifactory/api/npm/npm-local/
6. (Optional) Extra Security
- For automation or CI/CD, pass your credentials via environment variables or a CI secrets manager. Do not commit credentials or
.npmrc
with auth tokens to source control.
Summary Table
Step | Command/Action |
---|---|
New Project | npm init / npm init -y |
Add Files/Dependencies | Add code and run npm install <package> |
Configure Registry | Edit package.json / run npm login |
Set Credentials | npm login --registry=<artifactory_url> |
Publish Artifact | npm publish (uses registry from package.json or CLI) |
With these steps, you can create a Node.js project, configure it for npm, and securely publish your artifact to Artifactory using npm’s built-in tooling.
Another Method
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow , and SEO strategies at Wizbrand.
Do you want to learn Quantum Computing?
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at WIZBRAND