{"id":51014,"date":"2025-07-29T08:54:44","date_gmt":"2025-07-29T08:54:44","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=51014"},"modified":"2025-07-30T06:50:12","modified_gmt":"2025-07-30T06:50:12","slug":"artifacatory-upload-artifacts-to-artifactory-using-npm-with-node-js-project","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/artifacatory-upload-artifacts-to-artifactory-using-npm-with-node-js-project\/","title":{"rendered":"Artifacatory: Upload Artifacts to Artifactory using NPM with Node.js Project"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"step-by-step-guide-create-a-nodejs-project-with-np\">Step-by-Step Guide: Create a Node.js Project with npm and Upload Artifacts to Artifactory<\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">1. <strong>Install Prerequisites<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Node.js and npm:<\/strong> Download and install Node.js, which includes npm. Check installation with: text<code>node -v npm -v<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. <strong>Initialize a New Node.js Project<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a new directory for your project and navigate into it: text<code>mkdir my-node-project cd my-node-project<\/code><\/li>\n\n\n\n<li>Initialize a Node.js project with: text<code>npm init<\/code> Answer the prompts (project name, version, etc.) or use <code>npm init -y<\/code> to accept the defaults and generate <code>package.json<\/code><a href=\"https:\/\/philna.sh\/blog\/2019\/01\/10\/how-to-start-a-node-js-project\/\" target=\"_blank\" rel=\"noreferrer noopener\">1<\/a><a href=\"https:\/\/weaintplastic.github.io\/web-development-field-guide\/Development\/Frontend_Development\/Setting_up_your_project\/Setup_Dependency_Managers\/Node_Package_Manager\/Initialize_NPM_on_a_new_project.html\" target=\"_blank\" rel=\"noreferrer noopener\">2<\/a><a href=\"https:\/\/www.twilio.com\/docs\/usage\/tutorials\/how-to-set-up-your-node-js-and-express-development-environment\" target=\"_blank\" rel=\"noreferrer noopener\">3<\/a><a href=\"https:\/\/docs.npmjs.com\/creating-node-js-modules\/\" target=\"_blank\" rel=\"noreferrer noopener\">4<\/a><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Learn_web_development\/Extensions\/Server-side\/Express_Nodejs\/development_environment\" target=\"_blank\" rel=\"noreferrer noopener\">5<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">3. <strong>Develop Your Node.js Artifact<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add your source files. Commonly, you\u2019ll have an <code>index.js<\/code> or <code>main.js<\/code>, and add dependencies as needed: text<code>npm install &lt;dependency><\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. <strong>Configure Artifactory for npm Publish<\/strong><\/h2>\n\n\n\n<h2 class=\"wp-block-heading\">a. <strong>Obtain Artifactory Information<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You need:\n<ul class=\"wp-block-list\">\n<li>Your Artifactory npm repository URL (e.g., <code>https:\/\/company.jfrog.io\/artifactory\/api\/npm\/npm-local\/<\/code>)<\/li>\n\n\n\n<li>Your Artifactory username and API key or password<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">b. <strong>Set the Registry in Your Project<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Add the <code>publishConfig<\/code> block to your <code>package.json<\/code> to specify the Artifactory registry: json<code>\"publishConfig\": { \"registry\": \"https:\/\/company.jfrog.io\/artifactory\/api\/npm\/npm-local\/\" }<\/code> Replace the URL with your actual Artifactory repository URL<a href=\"https:\/\/jfrog.com\/help\/r\/jfrog-artifactory-documentation\/publish-npm-packages-with-the-npm-cli\" target=\"_blank\" rel=\"noreferrer noopener\">6<\/a><a href=\"https:\/\/jfrog.com\/help\/r\/jfrog-artifactory-documentation\/deploy-npm-packages-npm-publish\" target=\"_blank\" rel=\"noreferrer noopener\">7<\/a><a href=\"https:\/\/jfrog.com\/help\/r\/how-to-troubleshoot-npm-problems\/npm-publish\" target=\"_blank\" rel=\"noreferrer noopener\">8<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">c. <strong>Authenticate npm with Artifactory<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To authenticate, run in your terminal (replace the URL with your Artifactory npm repository): text<code>npm login --registry=https:\/\/company.jfrog.io\/artifactory\/api\/npm\/npm-local\/<\/code> Enter your Artifactory credentials. This creates or updates the <code>.npmrc<\/code> file with authentication tokens for your registry<a href=\"https:\/\/jfrog.com\/help\/r\/jfrog-artifactory-documentation\/publish-npm-packages-with-the-npm-cli\" target=\"_blank\" rel=\"noreferrer noopener\">6<\/a><a href=\"https:\/\/jfrog.com\/help\/r\/jfrog-artifactory-documentation\/deploy-npm-packages-npm-publish\" target=\"_blank\" rel=\"noreferrer noopener\">7<\/a>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5. <strong>Publish Your Artifact to Artifactory<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Once you&#8217;re ready to upload: text<code>npm publish<\/code> This command will upload your package based on the configuration in <code>publishConfig<\/code>. Alternatively, you can override the registry in the publish command: text<code>npm publish --registry=https:\/\/company.jfrog.io\/artifactory\/api\/npm\/npm-local\/<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6. <strong>(Optional) Extra Security<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>For automation or CI\/CD, pass your credentials via environment variables or a CI secrets manager. Do not commit credentials or <code>.npmrc<\/code> with auth tokens to source control.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Summary Table<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Step<\/th><th>Command\/Action<\/th><\/tr><\/thead><tbody><tr><td>New Project<\/td><td><code>npm init<\/code> \/ <code>npm init -y<\/code><\/td><\/tr><tr><td>Add Files\/Dependencies<\/td><td>Add code and run <code>npm install &lt;package&gt;<\/code><\/td><\/tr><tr><td>Configure Registry<\/td><td>Edit <code>package.json<\/code> \/ run <code>npm login<\/code><\/td><\/tr><tr><td>Set Credentials<\/td><td><code>npm login --registry=&lt;artifactory_url&gt;<\/code><\/td><\/tr><tr><td>Publish Artifact<\/td><td><code>npm publish<\/code> (uses registry from package.json or CLI)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>With these steps, you can create a Node.js project, configure it for npm, and securely publish your artifact to Artifactory using npm&#8217;s built-in tooling.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Another Method<\/h2>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Step-by-Step Guide: Create a Node.js Project with npm and Upload Artifacts to Artifactory 1. Install Prerequisites 2. Initialize a New Node.js Project 3. Develop Your Node.js Artifact 4. Configure Artifactory&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[4879],"tags":[],"class_list":["post-51014","post","type-post","status-publish","format-standard","hentry","category-artifactory"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/51014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=51014"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/51014\/revisions"}],"predecessor-version":[{"id":51017,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/51014\/revisions\/51017"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=51014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=51014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=51014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}