{"id":296,"date":"2026-11-06T13:58:46","date_gmt":"2026-11-06T13:58:46","guid":{"rendered":"https:\/\/devdojo.co.in\/?p=296"},"modified":"2026-11-06T13:58:47","modified_gmt":"2026-11-06T13:58:47","slug":"nodejs-series-part-3-npm-package-json","status":"publish","type":"post","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/","title":{"rendered":"Node.js Part 3: npm and package.json: Installing and Managing Packages"},"content":{"rendered":"\n<div class=\"dd-post\">\n<style>\n.single article:has(.dd-hero) .entry-media{display:none}\n.dd-post{--navy:#0b1020;--blue:#3178c6;--violet:#7c5cff;--ink:#1f2433;--muted:#5b6275;--line:#e3e6ef;font-size:17px;line-height:1.75;color:var(--ink)}\n.dd-post h2{margin:2.2em 0 .6em;font-size:1.6em;line-height:1.3;scroll-margin-top:90px}\n.dd-post h3{margin:1.6em 0 .5em;font-size:1.22em;scroll-margin-top:90px}\n.dd-post a{color:var(--blue);text-decoration:underline;text-underline-offset:3px}\n.dd-post pre{background:#0f1430;color:#e6e9f5;padding:18px 20px;border-radius:12px;overflow-x:auto;line-height:1.6;border:1px solid #232a52;margin:1.2em 0;font-size:14.5px !important}\n.dd-post pre code{font-size:1em !important;background:none;color:inherit;padding:0;font-family:\"JetBrains Mono\",\"Fira Code\",Consolas,Menlo,monospace;white-space:pre}\n.dd-post :not(pre)>code{background:#eef1fb;color:#2b3a8f;padding:2px 6px;border-radius:5px;font-size:.9em}\n.dd-post .dd-file{display:inline-block;background:#151b3b;color:#c9d1ff;font:600 13px\/1 \"JetBrains Mono\",Consolas,monospace;padding:7px 12px;border-radius:8px 8px 0 0;margin:1em 0 -1.2em;position:relative}\n.dd-post .dd-hero{margin:0 0 1.6em;border-radius:16px;overflow:hidden;box-shadow:0 10px 30px rgba(11,16,32,.25)}\n.dd-post .dd-hero svg{display:block;width:100%;height:auto}\n.dd-post .dd-hero .node{transition:transform .25s,filter .25s;transform-box:fill-box;transform-origin:center;cursor:pointer}\n.dd-post .dd-hero .node:hover{transform:scale(1.08);filter:drop-shadow(0 0 10px #7c5cff)}\n.dd-post .dd-series{display:inline-flex;align-items:center;gap:8px;background:#151b3b;color:#dfe3ff;border-radius:999px;padding:6px 14px;font-size:.88em;font-weight:600;margin:0 0 .8em}\n.dd-post .dd-series span{background:var(--violet);color:#fff;border-radius:999px;padding:2px 10px}\n.dd-post .dd-prereq{font-size:.96em;color:var(--muted);border-left:3px solid var(--line);padding-left:12px;margin:.6em 0 1.2em}\n.dd-post .dd-summary{background:linear-gradient(135deg,#eef3ff,#f4efff);border:1px solid #d6dcf5;border-left:5px solid var(--violet);border-radius:12px;padding:18px 22px;margin:1.4em 0}\n.dd-post .dd-summary strong.lbl{display:block;font-size:1.05em;margin-bottom:6px;color:#3a2fa0}\n.dd-post .dd-summary ul{margin:.3em 0 0 1.1em}\n.dd-post .dd-toc{background:#f8f9fc;border:1px solid var(--line);border-radius:12px;padding:16px 22px;margin:1.4em 0}\n.dd-post .dd-toc ol{margin:.4em 0 0 1.2em;columns:2;column-gap:28px}\n.dd-post .dd-toc li{break-inside:avoid;margin:.15em 0}\n@media(max-width:640px){.dd-post .dd-toc ol{columns:1}}\n.dd-post .dd-tip,.dd-post .dd-note,.dd-post .dd-warn{border-radius:10px;padding:14px 18px;margin:1.3em 0}\n.dd-post .dd-tip{background:#ecfbf3;border-left:4px solid #1f9d61}\n.dd-post .dd-note{background:#eef4ff;border-left:4px solid var(--blue)}\n.dd-post .dd-warn{background:#fff6e8;border-left:4px solid #e08a00}\n.dd-post .dd-cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px;margin:1.3em 0}\n.dd-post .dd-card{border:1px solid var(--line);border-radius:12px;padding:14px 16px;background:#fff;box-shadow:0 2px 8px rgba(20,30,70,.05)}\n.dd-post .dd-card b{display:block;color:#3a2fa0;margin-bottom:4px}\n.dd-post table{width:100%;border-collapse:collapse;margin:1.3em 0;font-size:.95em}\n.dd-post th,.dd-post td{border:1px solid var(--line);padding:10px 12px;text-align:left;vertical-align:top}\n.dd-post th{background:#151b3b;color:#fff}\n.dd-post tr:nth-child(even) td{background:#f8f9fc}\n.dd-post .dd-tablewrap{overflow-x:auto}\n.dd-post figure{margin:1.6em 0;text-align:center}\n.dd-post figure svg{width:100%;height:auto;border-radius:12px}\n.dd-post figcaption{font-size:.9em;color:var(--muted);margin-top:8px}\n.dd-post details{border:1px solid var(--line);border-radius:10px;padding:12px 16px;margin:.7em 0;background:#fff}\n.dd-post details summary{cursor:pointer;font-weight:600}\n.dd-post details[open] summary{margin-bottom:8px;color:#3a2fa0}\n.dd-post .dd-roadmap{border:2px solid #d6dcf5;background:#fbfbff}\n.dd-post .dd-roadmap h4{margin:1em 0 .3em;color:#151b3b;font-size:1em;text-transform:uppercase;letter-spacing:.04em}\n.dd-post .dd-roadmap ol{margin:.2em 0 .6em 1.4em;padding:0}\n.dd-post .dd-roadmap li{margin:.2em 0}\n.dd-post .dd-roadmap .here{background:var(--violet);color:#fff;border-radius:999px;padding:1px 9px;font-size:.8em;font-weight:700;margin-left:6px}\n.dd-post .dd-roadmap .soon{color:#8a90a6;font-size:.82em;margin-left:6px}\n.dd-post .dd-tabs{border:1px solid var(--line);border-radius:12px;padding:6px 16px 16px;margin:1.4em 0;background:#fbfbfe}\n.dd-post .dd-tabs>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-tabs .labels label{display:inline-block;padding:8px 16px;margin:10px 6px 0 0;border-radius:999px;border:1px solid #cfd5ea;cursor:pointer;font-weight:600;font-size:.95em;background:#fff;transition:background .2s}\n.dd-post .dd-tabs .labels label:hover{border-color:var(--violet)}\n.dd-post .dd-tabs .panel{display:none;margin-top:12px}\n.dd-post .dd-tabs #ti1:checked~.labels label[for=ti1],.dd-post .dd-tabs #ti2:checked~.labels label[for=ti2],.dd-post .dd-tabs #ti3:checked~.labels label[for=ti3],.dd-post .dd-tabs #ti4:checked~.labels label[for=ti4]{background:var(--violet);color:#fff;border-color:var(--violet)}\n.dd-post .dd-tabs #ti1:checked~.p1,.dd-post .dd-tabs #ti2:checked~.p2,.dd-post .dd-tabs #ti3:checked~.p3,.dd-post .dd-tabs #ti4:checked~.p4{display:block}\n.dd-post .dd-tabs #ti1:focus-visible~.labels label[for=ti1],.dd-post .dd-tabs #ti2:focus-visible~.labels label[for=ti2],.dd-post .dd-tabs #ti3:focus-visible~.labels label[for=ti3],.dd-post .dd-tabs #ti4:focus-visible~.labels label[for=ti4]{outline:2px solid var(--blue);outline-offset:2px}\n.dd-post .dd-cta{background:linear-gradient(135deg,#0b1020,#151b3b);color:#e8ebff;border-radius:16px;padding:24px 26px;margin:2em 0;text-align:center}\n.dd-post .dd-cta h3{color:#fff;margin-top:0}\n.dd-post .dd-cta a{color:#a99bff}\n.dd-post .dd-vsc{position:relative;margin:1.5em 0;border-radius:12px;overflow:hidden;background:#1e1e1e;border:1px solid #2b2b2b;box-shadow:0 14px 34px rgba(0,0,0,.28);font-family:\"Segoe UI\",system-ui,sans-serif}\n.dd-post .dd-vsc>input{position:absolute;opacity:0;pointer-events:none}\n.dd-post .dd-vsc-bar{display:flex;align-items:center;gap:12px;background:#323233;color:#cccccc;font-size:12.5px;padding:8px 12px}\n.dd-post .dd-dots{display:inline-flex;gap:7px}.dd-post .dd-dots i{width:12px;height:12px;border-radius:50%;background:#ff5f57;display:block}.dd-post .dd-dots i:nth-child(2){background:#febc2e}.dd-post .dd-dots i:nth-child(3){background:#28c840}\n.dd-post .dd-vsc-title{flex:1;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-right:50px;opacity:.85}\n.dd-post .dd-vsc-tabs{display:flex;align-items:stretch;background:#252526;border-bottom:1px solid #1e1e1e;overflow-x:auto}\n.dd-post .dd-vsc-tabs label{display:flex;align-items:center;gap:7px;padding:9px 16px;color:#969696;font-size:13px;cursor:pointer;background:#2d2d2d;border-right:1px solid #252526;border-top:1px solid transparent;white-space:nowrap;margin:0;transition:color .15s}\n.dd-post .dd-vsc-tabs label:hover{color:#e0e0e0}\n.dd-post .dd-vsc-tabs .ic{font:700 9.5px\/1 Consolas,monospace;padding:3px 4px;border-radius:3px;color:#1e1e1e}\n.dd-post .ic.py{background:#ffd43b}.dd-post .ic.js{background:#f1e05a}.dd-post .ic.sh{background:#89e051}\n.dd-post .dd-vsc-tabs label.run{margin-left:auto;background:transparent;border:0;color:#89d185;font-weight:600;display:none}\n.dd-post .dd-vsc-tabs label.run:hover{color:#b5f0b0;background:#2a2d2e}\n.dd-post .dd-vsc-pane{display:none}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .t3{background:#1e1e1e;color:#ffffff;border-top-color:#3178c6}\n.dd-post .dd-vsc>.f1:checked~.p1,.dd-post .dd-vsc>.f2:checked~.p2,.dd-post .dd-vsc>.f3:checked~.p3{display:block}\n.dd-post .dd-vsc>.f1:checked~.dd-vsc-tabs .run1,.dd-post .dd-vsc>.f2:checked~.dd-vsc-tabs .run2,.dd-post .dd-vsc>.f3:checked~.dd-vsc-tabs .run3{display:flex}\n.dd-post .dd-vsc>.f1:focus-visible~.dd-vsc-tabs .t1,.dd-post .dd-vsc>.f2:focus-visible~.dd-vsc-tabs .t2,.dd-post .dd-vsc>.f3:focus-visible~.dd-vsc-tabs .t3,.dd-post .dd-vsc>input[type=checkbox]:focus-visible~.dd-vsc-tabs .run{outline:2px solid #3178c6;outline-offset:-2px}\n.dd-post .dd-vsc-crumbs{background:#1e1e1e;color:#a9a9a9;font-size:12px;padding:5px 16px 2px}\n.dd-post .dd-vsc pre.dd-vsc-code{background:#1e1e1e;color:#d4d4d4;border:0;border-radius:0;margin:0;padding:8px 0 14px;counter-reset:ln;line-height:1.62;overflow-x:auto}\n.dd-post .dd-vsc pre code{font-family:Consolas,\"JetBrains Mono\",\"Fira Code\",Menlo,monospace;color:inherit;background:none;white-space:pre}\n.dd-post .dd-vsc .l{display:inline-block;min-width:100%;padding-right:18px;box-sizing:border-box}\n.dd-post .dd-vsc .l::before{counter-increment:ln;content:counter(ln);display:inline-block;width:3.2em;padding-right:1.4em;text-align:right;color:#6e7681;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc .l:hover{background:#2a2d2e}.dd-post .dd-vsc .l:hover::before{color:#c6c6c6}\n.dd-post .dd-vsc .k,.dd-post .dd-vsc .kn{color:#c586c0}.dd-post .dd-vsc .kc{color:#569cd6}.dd-post .dd-vsc .s{color:#ce9178}.dd-post .dd-vsc .c{color:#6a9955}.dd-post .dd-vsc .m{color:#b5cea8}.dd-post .dd-vsc .nf{color:#dcdcaa}.dd-post .dd-vsc .nc{color:#4ec9b0}.dd-post .dd-vsc .nb{color:#4ec9b0}.dd-post .dd-vsc .nd{color:#dcdcaa}.dd-post .dd-vsc .n{color:#9cdcfe}.dd-post .dd-vsc .o{color:#d4d4d4}.dd-post .dd-vsc .gp{color:#89d185;user-select:none;-webkit-user-select:none}\n.dd-post .dd-vsc-term{display:none;border-top:1px solid #3c3c3c;background:#181818}\n.dd-post .dd-vsc>.r1:checked~.p1 .dd-vsc-term,.dd-post .dd-vsc>.r2:checked~.p2 .dd-vsc-term,.dd-post .dd-vsc>.r3:checked~.p3 .dd-vsc-term{display:block;animation:ddterm .35s ease-out}\n@keyframes ddterm{from{opacity:0;transform:translateY(6px)}to{opacity:1;transform:none}}\n.dd-post .dd-term-head{display:flex;gap:18px;align-items:center;font-size:11px;letter-spacing:.06em;color:#8b8b8b;padding:7px 16px 0}\n.dd-post .dd-term-head span:first-child{color:#e7e7e7;border-bottom:1px solid #e7e7e7;padding-bottom:4px}\n.dd-post .dd-term-head .dd-term-note{margin-left:auto;letter-spacing:0;text-transform:none;color:#d7ba7d;border:0;font-size:11.5px}\n.dd-post .dd-vsc-term pre{background:#181818;color:#cccccc;border:0;margin:0;padding:10px 16px 14px;border-radius:0}\n.dd-post .dd-vsc-status{display:flex;flex-wrap:wrap;gap:4px 14px;background:#007acc;color:#fff;font-size:11.5px;padding:4px 12px}\n.dd-post .dd-vsc-status .sp{flex:1}\n.dd-post .dd-vsc-termonly pre.dd-vsc-code{background:#181818;padding:12px 16px}\n@media(max-width:640px){.dd-post .dd-vsc-title{padding-right:0;text-align:left}.dd-post .dd-vsc-status span:nth-child(n+4){display:none}.dd-post .dd-vsc .l::before{width:2.2em;padding-right:1em}}\n.dd-post .dd-vsc-hint{font-size:.93em;color:var(--muted);margin-top:-.6em}\n.dd-post .dd-next{border:1px dashed var(--violet);border-radius:12px;padding:16px 20px;margin:1.6em 0;background:#f7f4ff}\n.dd-post .ic.yml{background:#cb3837;color:#fff}\n.dd-post .ic.jsx{background:#61dafb}.dd-post .ic.html{background:#e44d26;color:#fff}.dd-post .ic.css{background:#563d7c;color:#fff}\n.dd-post .dd-steps{counter-reset:st;list-style:none;margin:1.2em 0;padding:0}\n.dd-post .dd-steps>li{position:relative;padding:0 0 0 46px;margin:0 0 14px}\n.dd-post .dd-steps>li::before{counter-increment:st;content:counter(st);position:absolute;left:0;top:2px;width:32px;height:32px;border-radius:50%;background:linear-gradient(135deg,#3178c6,#7c5cff);color:#fff;font-weight:700;text-align:center;line-height:32px}\n<\/style>\n<style>\n.dd-post .ic.json{background:#cbcb41}\n<\/style>\n\n<div class=\"dd-hero\">\n<svg viewBox=\"0 0 1200 520\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Node.js series Part 3 banner: packages flow from the npm registry through npm install into node_modules, recorded in package.json and package-lock.json\">\n<defs>\n<linearGradient id=\"ddbg\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\"><stop offset=\"0\" stop-color=\"#0b1020\"\/><stop offset=\"1\" stop-color=\"#151b3b\"\/><\/linearGradient>\n<linearGradient id=\"ddac\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient>\n<radialGradient id=\"ddglow\" cx=\".5\" cy=\".5\" r=\".5\"><stop offset=\"0\" stop-color=\"#7c5cff\" stop-opacity=\".45\"\/><stop offset=\"1\" stop-color=\"#7c5cff\" stop-opacity=\"0\"\/><\/radialGradient>\n<\/defs>\n<rect x=\"0\" y=\"-60\" width=\"1200\" height=\"640\" fill=\"url(#ddbg)\"\/>\n<circle cx=\"900\" cy=\"300\" r=\"280\" fill=\"url(#ddglow)\"\/>\n<g opacity=\".12\" stroke=\"#9fb2ff\"><path d=\"M0 100H1200M0 200H1200M0 300H1200M0 400H1200M200 0V520M400 0V520M600 0V520M800 0V520M1000 0V520\"\/><\/g>\n<rect x=\"60\" y=\"46\" width=\"128\" height=\"38\" rx=\"19\" fill=\"url(#ddac)\"\/>\n<text x=\"124\" y=\"71\" text-anchor=\"middle\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">PART 3<\/text>\n<text x=\"204\" y=\"71\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"18\" fill=\"#aab4e8\">Node.js Series \u00b7 DevDojo<\/text>\n<text x=\"60\" y=\"148\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"54\" font-weight=\"800\" fill=\"#ffffff\">npm and package.json<\/text>\n<text x=\"60\" y=\"206\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"40\" font-weight=\"800\" fill=\"url(#ddac)\">Install and Manage Packages<\/text>\n<text x=\"60\" y=\"250\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"23\" fill=\"#c9d1ff\">dependencies, version ranges, lock files and npm scripts<\/text>\n<g class=\"node\"><rect x=\"60\" y=\"300\" width=\"250\" height=\"70\" rx=\"14\" fill=\"#0b1020\" stroke=\"#cb3837\" stroke-width=\"2.5\"\/><text x=\"185\" y=\"330\" text-anchor=\"middle\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"20\" font-weight=\"800\" fill=\"#ff6b6b\">npm registry<\/text><text x=\"185\" y=\"356\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"15\" fill=\"#c9d1ff\">3M+ packages<\/text><\/g>\n<g class=\"node\"><rect x=\"60\" y=\"398\" width=\"250\" height=\"56\" rx=\"28\" fill=\"url(#ddac)\"\/><text x=\"185\" y=\"433\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">$ npm install dayjs<\/text><\/g>\n<path d=\"M310 335H380V380H440\" stroke=\"#7c5cff\" stroke-width=\"2.5\" fill=\"none\" opacity=\".8\"\/>\n<path d=\"M310 426H380V380\" stroke=\"#7c5cff\" stroke-width=\"2.5\" fill=\"none\" opacity=\".8\"\/>\n<path id=\"ddflow\" d=\"M310 335H380V380H440\" fill=\"none\" stroke=\"none\"\/>\n<circle r=\"6\" fill=\"#ff6b6b\"><animateMotion dur=\"2.4s\" repeatCount=\"indefinite\"><mpath href=\"#ddflow\"\/><\/animateMotion><\/circle>\n<path id=\"ddflow2\" d=\"M310 426H380V380H440\" fill=\"none\" stroke=\"none\"\/>\n<circle r=\"6\" fill=\"#61dafb\"><animateMotion dur=\"2.4s\" begin=\"1.2s\" repeatCount=\"indefinite\"><mpath href=\"#ddflow2\"\/><\/animateMotion><\/circle>\n<g class=\"node\"><rect x=\"440\" y=\"350\" width=\"170\" height=\"60\" rx=\"12\" fill=\"#151b3b\" stroke=\"#3178c6\" stroke-width=\"2.5\"\/><text x=\"525\" y=\"387\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"18\" fill=\"#e6e9ff\">node_modules<\/text><\/g>\n<g transform=\"translate(900 300)\">\n<path id=\"ddo1\" d=\"M-200 0 A200 82 0 1 1 200 0 A200 82 0 1 1 -200 0 Z\" fill=\"none\" stroke=\"url(#ddac)\" stroke-width=\"3\" opacity=\".7\"\/>\n<g class=\"node\"><rect x=\"-75\" y=\"-56\" width=\"150\" height=\"112\" rx=\"16\" fill=\"#cb3837\" stroke=\"#ff8a8a\" stroke-width=\"3\"\/><text y=\"-6\" text-anchor=\"middle\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"38\" font-weight=\"900\" fill=\"#fff\">npm<\/text><text y=\"28\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"14\" fill=\"#ffe1e1\">package manager<\/text><\/g>\n<g class=\"node\"><rect x=\"-250\" y=\"-140\" width=\"150\" height=\"40\" rx=\"10\" fill=\"#151b3b\" stroke=\"#cbcb41\" stroke-width=\"2\"\/><text x=\"-175\" y=\"-114\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"15\" fill=\"#f1f18a\">package.json<\/text><\/g>\n<g class=\"node\"><rect x=\"90\" y=\"-140\" width=\"190\" height=\"40\" rx=\"10\" fill=\"#151b3b\" stroke=\"#cbcb41\" stroke-width=\"2\"\/><text x=\"185\" y=\"-114\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"15\" fill=\"#f1f18a\">package-lock.json<\/text><\/g>\n<g class=\"node\"><rect x=\"-75\" y=\"96\" width=\"150\" height=\"40\" rx=\"10\" fill=\"#151b3b\" stroke=\"#89d185\" stroke-width=\"2\"\/><text x=\"0\" y=\"122\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"15\" fill=\"#b5f0b0\">npm run dev<\/text><\/g>\n<circle r=\"9\" fill=\"#ffffff\"><animateMotion dur=\"5s\" repeatCount=\"indefinite\"><mpath href=\"#ddo1\"\/><\/animateMotion><\/circle>\n<circle r=\"8\" fill=\"#7c5cff\"><animateMotion dur=\"5s\" begin=\"-2.5s\" repeatCount=\"indefinite\"><mpath href=\"#ddo1\"\/><\/animateMotion><\/circle>\n<\/g>\n<text x=\"700\" y=\"490\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"17\" fill=\"#aab4e8\">Reuse great code instead of writing it all yourself<\/text>\n<text x=\"60\" y=\"505\" font-family=\"Segoe UI,Arial,sans-serif\" font-size=\"16\" fill=\"#7f89b5\">devdojo.co.in \u00b7 Beginner friendly \u00b7 Works on Node.js 22, 24 and 26<\/text>\n<\/svg>\n<\/div>\n\n<div class=\"dd-series\">Series: Node.js <span>Part 3 of 30<\/span><\/div>\n<p class=\"dd-prereq\"><strong>What you should know first:<\/strong> read <a href=\"https:\/\/devdojo.co.in\/index.php\/2026\/10\/23\/nodejs-series-part-1-what-is-nodejs\/\">Node.js Part 1: What Is Node.js<\/a> and <a href=\"https:\/\/devdojo.co.in\/index.php\/2026\/10\/30\/nodejs-series-part-2-modules-esm-commonjs\/\">Node.js Part 2: Modules in Node.js<\/a>. You should know how to run a file with <code>node file.js<\/code> and how <code>import<\/code> \/ <code>export<\/code> work.<\/p>\n\n<p>In Part 2 you split your own code into modules. But most code in a real Node.js app is not written by you. Date formatting, web frameworks, database drivers, testing tools: someone has already built them and shared them for free. <strong>npm and package.json<\/strong> are how you find, install and manage that shared code. In this part you will learn, step by step, what npm is, what every important line of <code>package.json<\/code> means, how to install and remove packages, what the strange <code>^<\/code> and <code>~<\/code> symbols in version numbers mean, why <code>package-lock.json<\/code> exists, and how to run your project with <strong>npm scripts<\/strong>.<\/p>\n\n<div class=\"dd-summary\">\n<strong class=\"lbl\">Quick Summary<\/strong>\n<ul>\n<li><strong>npm<\/strong> is the package manager that comes with Node.js. It downloads packages from the <strong>npm registry<\/strong>, a huge online library of free JavaScript code.<\/li>\n<li><strong>package.json<\/strong> is your project\u2019s ID card: name, version, scripts and the list of packages your project needs.<\/li>\n<li><code>npm install name<\/code> adds a package to <strong>dependencies<\/strong>; <code>npm install -D name<\/code> adds a development-only tool to <strong>devDependencies<\/strong>.<\/li>\n<li>Versions follow <strong>MAJOR.MINOR.PATCH<\/strong>. <code>^1.11.0<\/code> allows minor and patch updates; <code>~1.11.0<\/code> allows only patch updates.<\/li>\n<li><strong>package-lock.json<\/strong> records the exact versions installed. Commit it, and use <code>npm ci<\/code> on servers and in CI for identical installs.<\/li>\n<li><strong>npm scripts<\/strong> (<code>npm start<\/code>, <code>npm run dev<\/code>, <code>npm test<\/code>) give every project the same simple commands.<\/li>\n<\/ul>\n<\/div>\n\n<details class=\"dd-roadmap\">\n<summary>Full Node.js roadmap (30 parts)<\/summary>\n<h4>Beginner<\/h4>\n<ol start=\"1\">\n<li><a href=\"https:\/\/devdojo.co.in\/index.php\/2026\/10\/23\/nodejs-series-part-1-what-is-nodejs\/\">What Is Node.js and How to Build Your First Node.js App<\/a><\/li>\n<li><a href=\"https:\/\/devdojo.co.in\/index.php\/2026\/10\/30\/nodejs-series-part-2-modules-esm-commonjs\/\">Modules in Node.js: ES Modules, CommonJS and import\/export<\/a><\/li>\n<li>npm and package.json: Installing and Managing Packages <span class=\"here\">You are here<\/span><\/li>\n<li>Working with Files and Folders: the fs and path Modules <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Asynchronous Node.js: Callbacks, Promises and async\/await <span class=\"soon\">Coming soon<\/span><\/li>\n<li>The Event Loop Explained Simply <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Events and EventEmitter: Building Event-Driven Code <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Streams and Buffers: Handling Large Data Efficiently <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Building a Web Server with the http Module <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Mini Project: Build a Command-Line Tool with Node.js <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<h4>Intermediate<\/h4>\n<ol start=\"11\">\n<li>Express.js Basics: Routes, Requests and Responses <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Middleware in Express: How Requests Flow <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Build a REST API with Express: Full CRUD <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Validating Request Data with Zod <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Environment Variables and Configuration (&#8211;env-file and .env) <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Connecting Node.js to PostgreSQL <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Using an ORM: Prisma vs Drizzle <span class=\"soon\">Coming soon<\/span><\/li>\n<li>MongoDB with Mongoose <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Authentication: Password Hashing, Sessions and JWT <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Error Handling and Logging with Pino <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<h4>Advanced<\/h4>\n<ol start=\"21\">\n<li>Testing Node.js Apps with node:test and Supertest <span class=\"soon\">Coming soon<\/span><\/li>\n<li>TypeScript with Node.js: Running .ts Files Directly <span class=\"soon\">Coming soon<\/span><\/li>\n<li>File Uploads and Image Processing <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Real-Time Apps with WebSockets and Socket.IO <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Caching with Redis <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Background Jobs and Queues with BullMQ <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Worker Threads and Clustering for Performance <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Security Best Practices for Node.js APIs <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Debugging, Profiling and Performance Tuning <span class=\"soon\">Coming soon<\/span><\/li>\n<li>Final Project: Build and Deploy a Production-Ready Node.js API <span class=\"soon\">Coming soon<\/span><\/li>\n<\/ol>\n<\/details>\n\n<nav class=\"dd-toc\" aria-label=\"Table of contents\">\n<strong>In this post<\/strong>\n<ol>\n<li><a href=\"#what-is-npm\">What is npm?<\/a><\/li>\n<li><a href=\"#create-package-json\">Create a package.json file<\/a><\/li>\n<li><a href=\"#package-json-fields\">package.json fields explained<\/a><\/li>\n<li><a href=\"#install\">Installing your first package<\/a><\/li>\n<li><a href=\"#dev-dependencies\">dependencies vs devDependencies<\/a><\/li>\n<li><a href=\"#versions\">Version numbers and ranges (^ and ~)<\/a><\/li>\n<li><a href=\"#lock-file\">package-lock.json and npm ci<\/a><\/li>\n<li><a href=\"#scripts\">npm scripts<\/a><\/li>\n<li><a href=\"#npx\">Running tools with npx<\/a><\/li>\n<li><a href=\"#update-remove\">Update, remove and audit packages<\/a><\/li>\n<li><a href=\"#errors\">Common errors and fixes<\/a><\/li>\n<li><a href=\"#best-practices\">Best practices<\/a><\/li>\n<li><a href=\"#practice\">Practice task<\/a><\/li>\n<li><a href=\"#faq\">FAQ<\/a><\/li>\n<\/ol>\n<\/nav>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"what-is-npm\">What is npm?<\/h2>\n<p><strong>npm<\/strong> (short for Node Package Manager) is installed automatically with Node.js. The word \u201cnpm\u201d is used for three connected things:<\/p>\n<div class=\"dd-cards\">\n<div class=\"dd-card\"><b>1. The registry<\/b>A huge free online library at <code>registry.npmjs.org<\/code> with millions of packages that anyone can download.<\/div>\n<div class=\"dd-card\"><b>2. The command-line tool<\/b>The <code>npm<\/code> command in your terminal. It installs, updates and removes packages and runs scripts.<\/div>\n<div class=\"dd-card\"><b>3. The website<\/b><a href=\"https:\/\/www.npmjs.com\/\" target=\"_blank\" rel=\"noopener\">npmjs.com<\/a>, where you search packages, read their docs and check weekly downloads.<\/div>\n<\/div>\n<p>A <strong>package<\/strong> is simply a folder of code with its own <code>package.json<\/code>. When you install one, you can <code>import<\/code> it exactly like the modules you wrote in Part 2. Check that npm is ready:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># npm comes with Node.js, so both commands should print a version<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> node -v<\/span>\n<span class=\"l\">v22.23.4<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm -v<\/span>\n<span class=\"l\">10.9.9<\/span><\/code><\/pre>\n<\/div>\n<p>Your numbers may be higher, and that is fine. Everything in this tutorial works with the npm version that ships with Node.js 22, 24 or 26.<\/p>\n\n<h2 id=\"create-package-json\">Create a package.json file<\/h2>\n<p>Every Node.js project starts with a <code>package.json<\/code> file in its main folder. You can write it by hand, but the quickest way is <code>npm init<\/code>. The <code>-y<\/code> flag answers \u201cyes\u201d to every question and uses default values.<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># create a new project folder and a package.json inside it<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> mkdir my-first-npm-app<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> cd my-first-npm-app<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm init -y<\/span>\n<span class=\"l\">Wrote to \/home\/you\/my-first-npm-app\/package.json:<\/span><\/code><\/pre>\n<\/div>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: package.json\">\n<input type=\"radio\" name=\"v1\" id=\"v1f1\" class=\"f1\" checked>\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">package.json \u2014 my-first-npm-app \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v1f1\" class=\"t1\"><b class=\"ic json\">{}<\/b>package.json<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">my-first-npm-app \u203a package.json<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\">{<\/span>\n<span class=\"l\">  <span class=\"n\">\"name\"<\/span>: <span class=\"s\">\"my-first-npm-app\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"version\"<\/span>: <span class=\"s\">\"1.0.0\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"description\"<\/span>: <span class=\"s\">\"\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"main\"<\/span>: <span class=\"s\">\"index.js\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"scripts\"<\/span>: {<\/span>\n<span class=\"l\">    <span class=\"n\">\"test\"<\/span>: <span class=\"s\">\"echo \\\"Error: no test specified\\\" &amp;&amp; exit 1\"<\/span><\/span>\n<span class=\"l\">  },<\/span>\n<span class=\"l\">  <span class=\"n\">\"keywords\"<\/span>: [],<\/span>\n<span class=\"l\">  <span class=\"n\">\"author\"<\/span>: <span class=\"s\">\"\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"license\"<\/span>: <span class=\"s\">\"ISC\"<\/span><\/span>\n<span class=\"l\">}<\/span><\/code><\/pre>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 12, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JSON<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">This is the file <code>npm init -y<\/code> created. Hover a line to highlight it.<\/p>\n<p>Two quick improvements you will want in almost every new project: switch to ES modules and add a description. You can edit the file in your editor or use the <code>npm pkg<\/code> command, which edits <code>package.json<\/code> safely for you:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> npm pkg set type=module<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm pkg set description=\"My first app with npm packages\"<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm pkg get type<\/span>\n<span class=\"l\">\"module\"<\/span><\/code><\/pre>\n<\/div>\n\n<h2 id=\"package-json-fields\">package.json fields explained<\/h2>\n<p>You do not need to memorise every field. These are the ones you will use every week. Click the tabs to explore them:<\/p>\n<div class=\"dd-tabs\" role=\"group\" aria-label=\"package.json fields explorer\">\n<input type=\"radio\" name=\"ti\" id=\"ti1\" checked>\n<input type=\"radio\" name=\"ti\" id=\"ti2\">\n<input type=\"radio\" name=\"ti\" id=\"ti3\">\n<input type=\"radio\" name=\"ti\" id=\"ti4\">\n<div class=\"labels\"><label for=\"ti1\">Identity<\/label><label for=\"ti2\">type &amp; engines<\/label><label for=\"ti3\">scripts<\/label><label for=\"ti4\">dependencies<\/label><\/div>\n<div class=\"panel p1\"><p><strong><code>name<\/code> and <code>version<\/code><\/strong> identify your project. The name must be lowercase with no spaces (use dashes). The version follows <code>MAJOR.MINOR.PATCH<\/code>, for example <code>1.0.0<\/code>. <code>description<\/code>, <code>keywords<\/code>, <code>author<\/code> and <code>license<\/code> are extra information, mostly useful if you publish the package. <code>\"private\": true<\/code> stops you from publishing an app to npm by mistake.<\/p><\/div>\n<div class=\"panel p2\"><p><strong><code>\"type\": \"module\"<\/code><\/strong> tells Node.js that <code>.js<\/code> files in this project are ES modules, so you can use <code>import<\/code> and <code>export<\/code> (you learned this in Part 2). <strong><code>engines<\/code><\/strong> documents which Node.js versions your app supports, for example <code>\"node\": \"&gt;=22\"<\/code>. <code>main<\/code> is the entry file for people who import your package; for an app you can remove it.<\/p><\/div>\n<div class=\"panel p3\"><p><strong><code>scripts<\/code><\/strong> are named shortcuts for commands. <code>\"start\": \"node app.js\"<\/code> lets anyone run <code>npm start<\/code> without knowing which file to open. Scripts can use tools installed in <code>node_modules\/.bin<\/code> without a global install.<\/p><\/div>\n<div class=\"panel p4\"><p><strong><code>dependencies<\/code><\/strong> are packages your app needs to <em>run<\/em> (for example <code>dayjs<\/code>, <code>express<\/code>). <strong><code>devDependencies<\/code><\/strong> are tools you need only while <em>developing<\/em> (test runners, linters, TypeScript). Each entry is a package name plus a <strong>version range<\/strong> such as <code>\"^1.11.23\"<\/code>.<\/p><\/div>\n<\/div>\n<p>The full list of fields is in the official <a href=\"https:\/\/docs.npmjs.com\/cli\/configuring-npm\/package-json\" target=\"_blank\" rel=\"noopener\">npm package.json documentation<\/a>.<\/p>\n\n<h2 id=\"install\">Installing your first npm package<\/h2>\n<p>Let us install <a href=\"https:\/\/www.npmjs.com\/package\/dayjs\" target=\"_blank\" rel=\"noopener\">dayjs<\/a>, a tiny and popular library for working with dates. Run this inside your project folder:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> npm install dayjs<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\">added 1 package, and audited 2 packages in 459ms<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\">found 0 vulnerabilities<\/span><\/code><\/pre>\n<\/div>\n<figure>\n<svg viewBox=\"0 0 900 300\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Diagram: npm install downloads a package from the npm registry into node_modules and records it in package.json and package-lock.json\">\n<rect width=\"900\" height=\"300\" rx=\"16\" fill=\"#0b1020\"\/>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<rect x=\"30\" y=\"110\" width=\"190\" height=\"80\" rx=\"14\" fill=\"#151b3b\" stroke=\"#cb3837\" stroke-width=\"2.5\"\/>\n<text x=\"125\" y=\"145\" text-anchor=\"middle\" font-size=\"20\" font-weight=\"800\" fill=\"#ff6b6b\">npm registry<\/text>\n<text x=\"125\" y=\"170\" text-anchor=\"middle\" font-size=\"14\" fill=\"#aab4e8\">registry.npmjs.org<\/text>\n<rect x=\"320\" y=\"115\" width=\"210\" height=\"70\" rx=\"35\" fill=\"url(#f1ac)\"\/>\n<text x=\"425\" y=\"157\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"18\" font-weight=\"700\" fill=\"#fff\">npm install dayjs<\/text>\n<rect x=\"640\" y=\"30\" width=\"230\" height=\"64\" rx=\"12\" fill=\"#151b3b\" stroke=\"#3178c6\" stroke-width=\"2\"\/>\n<text x=\"755\" y=\"58\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"17\" fill=\"#e6e9ff\">node_modules\/<\/text>\n<text x=\"755\" y=\"80\" text-anchor=\"middle\" font-size=\"13\" fill=\"#aab4e8\">the downloaded code<\/text>\n<rect x=\"640\" y=\"118\" width=\"230\" height=\"64\" rx=\"12\" fill=\"#151b3b\" stroke=\"#cbcb41\" stroke-width=\"2\"\/>\n<text x=\"755\" y=\"146\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"17\" fill=\"#f1f18a\">package.json<\/text>\n<text x=\"755\" y=\"168\" text-anchor=\"middle\" font-size=\"13\" fill=\"#aab4e8\">&#8220;dayjs&#8221;: &#8220;^1.11.23&#8221;<\/text>\n<rect x=\"640\" y=\"206\" width=\"230\" height=\"64\" rx=\"12\" fill=\"#151b3b\" stroke=\"#cbcb41\" stroke-width=\"2\"\/>\n<text x=\"755\" y=\"234\" text-anchor=\"middle\" font-family=\"Consolas,monospace\" font-size=\"17\" fill=\"#f1f18a\">package-lock.json<\/text>\n<text x=\"755\" y=\"256\" text-anchor=\"middle\" font-size=\"13\" fill=\"#aab4e8\">exact version 1.11.23<\/text>\n<\/g>\n<defs><linearGradient id=\"f1ac\" x1=\"0\" y1=\"0\" x2=\"1\" y2=\"0\"><stop offset=\"0\" stop-color=\"#3178c6\"\/><stop offset=\"1\" stop-color=\"#7c5cff\"\/><\/linearGradient>\n<marker id=\"f1ar\" viewBox=\"0 0 10 10\" refX=\"9\" refY=\"5\" markerWidth=\"7\" markerHeight=\"7\" orient=\"auto\"><path d=\"M0 0L10 5L0 10z\" fill=\"#7c5cff\"\/><\/marker><\/defs>\n<g stroke=\"#7c5cff\" stroke-width=\"2.5\" fill=\"none\" marker-end=\"url(#f1ar)\">\n<path d=\"M220 150H315\"\/><path d=\"M530 150C585 150 585 62 635 62\"\/><path d=\"M530 150H635\"\/><path d=\"M530 150C585 150 585 238 635 238\"\/>\n<\/g>\n<\/svg>\n<figcaption>One <code>npm install<\/code> command does three things: downloads the code into <code>node_modules<\/code>, adds the package to <code>package.json<\/code>, and writes the exact version to <code>package-lock.json<\/code>.<\/figcaption>\n<\/figure>\n<p>Now use the package. Because <code>dayjs<\/code> lives in <code>node_modules<\/code>, you import it by its <strong>package name<\/strong>, with no <code>.\/<\/code> and no file extension. That is how Node.js knows to look in <code>node_modules<\/code> instead of your own files.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: app.js\">\n<input type=\"radio\" name=\"v2\" id=\"v2f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v2r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">app.js \u2014 my-first-npm-app \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v2f1\" class=\"t1\"><b class=\"ic js\">JS<\/b>app.js<\/label>\n<label for=\"v2r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">my-first-npm-app \u203a app.js<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">\/\/ app.js \u2013 use an npm package like any other module<\/span><\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">dayjs<\/span> <span class=\"k\">from<\/span> <span class=\"s\">\"dayjs\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">launch<\/span> = <span class=\"nf\">dayjs<\/span>(<span class=\"s\">\"2026-12-25\"<\/span>);<\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">today<\/span> = <span class=\"nf\">dayjs<\/span>(<span class=\"s\">\"2026-11-06\"<\/span>);<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"nb\">console<\/span>.<span class=\"nf\">log<\/span>(<span class=\"s\">\"Launch date:\"<\/span>, <span class=\"n\">launch<\/span>.<span class=\"nf\">format<\/span>(<span class=\"s\">\"DD MMM YYYY\"<\/span>));<\/span>\n<span class=\"l\"><span class=\"nb\">console<\/span>.<span class=\"nf\">log<\/span>(<span class=\"s\">\"Days to go:\"<\/span>, <span class=\"n\">launch<\/span>.<span class=\"nf\">diff<\/span>(<span class=\"n\">today<\/span>, <span class=\"s\">\"day\"<\/span>));<\/span>\n<span class=\"l\"><span class=\"nb\">console<\/span>.<span class=\"nf\">log<\/span>(<span class=\"s\">\"One week later:\"<\/span>, <span class=\"n\">today<\/span>.<span class=\"nf\">add<\/span>(<span class=\"m\">7<\/span>, <span class=\"s\">\"day\"<\/span>).<span class=\"nf\">format<\/span>(<span class=\"s\">\"dddd, D MMMM\"<\/span>));<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Real output (Node.js 22, npm, Linux)<\/span><\/div><pre><code><span class=\"gp\">$<\/span> node app.js\nLaunch date: 25 Dec 2026\nDays to go: 49\nOne week later: Friday, 13 November<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 9, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong> to see the real output.<\/p>\n<div class=\"dd-tip\"><strong>Tip:<\/strong> <code>npm install<\/code> has a short form, <code>npm i<\/code>. Both do exactly the same thing. You can also install several packages at once: <code>npm i dayjs zod<\/code>.<\/div>\n<div class=\"dd-note\"><strong>Never edit or commit <code>node_modules<\/code>.<\/strong> It can contain thousands of files and is always re-created by <code>npm install<\/code>. Add it to your <code>.gitignore<\/code> file.<\/div>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"dev-dependencies\">dependencies vs devDependencies<\/h2>\n<p>Some packages are part of your running app. Others only help you while you write code. npm keeps them in two separate lists:<\/p>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th><\/th><th>dependencies<\/th><th>devDependencies<\/th><\/tr><\/thead>\n<tbody>\n<tr><td>Install command<\/td><td><code>npm install dayjs<\/code><\/td><td><code>npm install -D semver<\/code> (or <code>--save-dev<\/code>)<\/td><\/tr>\n<tr><td>Used for<\/td><td>Code your app needs to run<\/td><td>Tools for building, testing and checking code<\/td><\/tr>\n<tr><td>Examples<\/td><td>express, dayjs, zod, pg<\/td><td>typescript, eslint, prettier, vitest<\/td><\/tr>\n<tr><td>Installed in production?<\/td><td>Yes<\/td><td>No, when you use <code>npm ci --omit=dev<\/code><\/td><\/tr>\n<\/tbody><\/table><\/div>\n<p>For this tutorial we install <code>semver<\/code> (the same version-checking library that npm itself uses) as a dev dependency, because we only need it to experiment:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> npm install -D semver<\/span>\n<span class=\"l\">added 1 package, and audited 3 packages in 402ms<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\">found 0 vulnerabilities<\/span><\/code><\/pre>\n<\/div>\n\n<h2 id=\"versions\">Version numbers and ranges (^ and ~)<\/h2>\n<p>Look at <code>package.json<\/code> after installing and you will see <code>\"dayjs\": \"^1.11.23\"<\/code>. That little <code>^<\/code> is a <strong>version range<\/strong>. npm packages use <strong>semantic versioning<\/strong> (semver): <code>MAJOR.MINOR.PATCH<\/code>.<\/p>\n<figure>\n<svg viewBox=\"0 0 900 320\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" role=\"img\" aria-label=\"Diagram: a version number 1.11.23 split into MAJOR, MINOR and PATCH, with the caret range allowing minor and patch updates and the tilde range allowing only patch updates\">\n<rect width=\"900\" height=\"320\" rx=\"16\" fill=\"#0b1020\"\/>\n<g font-family=\"Segoe UI,Arial,sans-serif\" text-anchor=\"middle\">\n<g font-family=\"Consolas,monospace\" font-size=\"72\" font-weight=\"700\"><text x=\"330\" y=\"104\" fill=\"#ff6b6b\">1<\/text><text x=\"390\" y=\"104\" fill=\"#8a90a6\">.<\/text><text x=\"455\" y=\"104\" fill=\"#61dafb\">11<\/text><text x=\"520\" y=\"104\" fill=\"#8a90a6\">.<\/text><text x=\"585\" y=\"104\" fill=\"#89d185\">23<\/text><\/g>\n<text x=\"330\" y=\"146\" font-size=\"17\" font-weight=\"800\" fill=\"#ff6b6b\">MAJOR<\/text>\n<text x=\"455\" y=\"146\" font-size=\"17\" font-weight=\"800\" fill=\"#61dafb\">MINOR<\/text>\n<text x=\"585\" y=\"146\" font-size=\"17\" font-weight=\"800\" fill=\"#89d185\">PATCH<\/text>\n<text x=\"330\" y=\"168\" font-size=\"13\" fill=\"#aab4e8\">breaking changes<\/text>\n<text x=\"455\" y=\"168\" font-size=\"13\" fill=\"#aab4e8\">new features<\/text>\n<text x=\"585\" y=\"168\" font-size=\"13\" fill=\"#aab4e8\">bug fixes<\/text>\n<\/g>\n<g font-family=\"Segoe UI,Arial,sans-serif\">\n<rect x=\"60\" y=\"200\" width=\"370\" height=\"90\" rx=\"14\" fill=\"#151b3b\" stroke=\"#7c5cff\" stroke-width=\"2\"\/>\n<text x=\"84\" y=\"234\" font-family=\"Consolas,monospace\" font-size=\"22\" font-weight=\"700\" fill=\"#a99bff\">^1.11.0  caret<\/text>\n<text x=\"84\" y=\"264\" font-size=\"15\" fill=\"#dfe3ff\">accepts 1.11.23 and 1.12.0, not 2.0.0<\/text>\n<rect x=\"470\" y=\"200\" width=\"370\" height=\"90\" rx=\"14\" fill=\"#151b3b\" stroke=\"#3178c6\" stroke-width=\"2\"\/>\n<text x=\"494\" y=\"234\" font-family=\"Consolas,monospace\" font-size=\"22\" font-weight=\"700\" fill=\"#7fb4ff\">~1.11.0  tilde<\/text>\n<text x=\"494\" y=\"264\" font-size=\"15\" fill=\"#dfe3ff\">accepts 1.11.23, not 1.12.0<\/text>\n<\/g>\n<\/svg>\n<figcaption>Semantic versioning: the caret <code>^<\/code> (npm\u2019s default) allows new features and fixes; the tilde <code>~<\/code> allows only bug fixes.<\/figcaption>\n<\/figure>\n<p>Seeing is believing. This small script uses the <code>semver<\/code> package to check which versions each range accepts:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: versions.js\">\n<input type=\"radio\" name=\"v3\" id=\"v3f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v3r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">versions.js \u2014 my-first-npm-app \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v3f1\" class=\"t1\"><b class=\"ic js\">JS<\/b>versions.js<\/label>\n<label for=\"v3r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">my-first-npm-app \u203a versions.js<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\">\/\/ versions.js \u2013 see which versions a range accepts<\/span><\/span>\n<span class=\"l\"><span class=\"k\">import<\/span> <span class=\"n\">semver<\/span> <span class=\"k\">from<\/span> <span class=\"s\">\"semver\"<\/span>;<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">ranges<\/span> = [<span class=\"s\">\"^1.11.0\"<\/span>, <span class=\"s\">\"~1.11.0\"<\/span>, <span class=\"s\">\"1.11.0\"<\/span>, <span class=\"s\">\"&gt;=1.10.0 &lt;2.0.0\"<\/span>];<\/span>\n<span class=\"l\"><span class=\"k\">const<\/span> <span class=\"n\">versions<\/span> = [<span class=\"s\">\"1.11.0\"<\/span>, <span class=\"s\">\"1.11.23\"<\/span>, <span class=\"s\">\"1.12.0\"<\/span>, <span class=\"s\">\"2.0.0\"<\/span>];<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\"><span class=\"k\">for<\/span> (<span class=\"k\">const<\/span> <span class=\"n\">range<\/span> <span class=\"k\">of<\/span> <span class=\"n\">ranges<\/span>) {<\/span>\n<span class=\"l\">  <span class=\"k\">const<\/span> <span class=\"n\">ok<\/span> = <span class=\"n\">versions<\/span>.<span class=\"nf\">filter<\/span>((<span class=\"n\">v<\/span>) =&gt; <span class=\"n\">semver<\/span>.<span class=\"nf\">satisfies<\/span>(<span class=\"n\">v<\/span>, <span class=\"n\">range<\/span>));<\/span>\n<span class=\"l\">  <span class=\"nb\">console<\/span>.<span class=\"nf\">log<\/span>(<span class=\"n\">range<\/span>.<span class=\"nf\">padEnd<\/span>(<span class=\"m\">16<\/span>), <span class=\"s\">\"-&gt;\"<\/span>, <span class=\"n\">ok<\/span>.<span class=\"nf\">join<\/span>(<span class=\"s\">\", \"<\/span>));<\/span>\n<span class=\"l\">}<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Real output (Node.js 22, npm, Linux)<\/span><\/div><pre><code><span class=\"gp\">$<\/span> npm run versions\n&gt; my-first-npm-app@1.0.0 versions\n&gt; node versions.js\n\n^1.11.0          -&gt; 1.11.0, 1.11.23, 1.12.0\n~1.11.0          -&gt; 1.11.0, 1.11.23\n1.11.0           -&gt; 1.11.0\n&gt;=1.10.0 &lt;2.0.0  -&gt; 1.11.0, 1.11.23, 1.12.0<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 10, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JavaScript<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong> to see which versions every range allows (real output).<\/p>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Range<\/th><th>Meaning in simple words<\/th><th>When to use<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>^1.11.0<\/code><\/td><td>Any 1.x.x version from 1.11.0 up<\/td><td>Default. Good for most packages.<\/td><\/tr>\n<tr><td><code>~1.11.0<\/code><\/td><td>Only 1.11.x bug-fix versions<\/td><td>When a package sometimes breaks things in minor updates.<\/td><\/tr>\n<tr><td><code>1.11.0<\/code><\/td><td>Exactly this version<\/td><td>When you need full control (<code>npm i dayjs --save-exact<\/code>).<\/td><\/tr>\n<tr><td><code>*<\/code> or <code>latest<\/code><\/td><td>Any version at all<\/td><td>Avoid in real projects.<\/td><\/tr>\n<\/tbody><\/table><\/div>\n<div class=\"dd-warn\"><strong>Careful with 0.x versions:<\/strong> for packages below 1.0.0, <code>^0.4.2<\/code> only allows <code>0.4.x<\/code>, because in the 0.x stage every minor update may break things. Learn more at <a href=\"https:\/\/semver.org\/\" target=\"_blank\" rel=\"noopener\">semver.org<\/a>.<\/div>\n\n<h2 id=\"lock-file\">package-lock.json and npm ci<\/h2>\n<p>If <code>package.json<\/code> says <code>^1.11.23<\/code>, then today you may get 1.11.23 and next month your teammate may get 1.12.0. To avoid \u201cit works on my machine\u201d bugs, npm writes <strong>package-lock.json<\/strong>: the exact version, download URL and integrity hash of every installed package, including the packages that your packages depend on.<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: package-lock.json\">\n<input type=\"radio\" name=\"v4\" id=\"v4f1\" class=\"f1\" checked>\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">package-lock.json \u2014 my-first-npm-app \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v4f1\" class=\"t1\"><b class=\"ic json\">{}<\/b>package-lock.json<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">my-first-npm-app \u203a package-lock.json<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\">{<\/span>\n<span class=\"l\">  <span class=\"n\">\"name\"<\/span>: <span class=\"s\">\"my-first-npm-app\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"version\"<\/span>: <span class=\"s\">\"1.0.0\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"lockfileVersion\"<\/span>: <span class=\"m\">3<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"requires\"<\/span>: <span class=\"kc\">true<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"packages\"<\/span>: {<\/span>\n<span class=\"l\">    <span class=\"n\">\"node_modules\/dayjs\"<\/span>: {<\/span>\n<span class=\"l\">      <span class=\"n\">\"version\"<\/span>: <span class=\"s\">\"1.11.23\"<\/span>,<\/span>\n<span class=\"l\">      <span class=\"n\">\"resolved\"<\/span>: <span class=\"s\">\"https:\/\/registry.npmjs.org\/dayjs\/-\/dayjs-1.11.23.tgz\"<\/span>,<\/span>\n<span class=\"l\">      <span class=\"n\">\"integrity\"<\/span>: <span class=\"s\">\"sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ\/...\"<\/span>,<\/span>\n<span class=\"l\">      <span class=\"n\">\"license\"<\/span>: <span class=\"s\">\"MIT\"<\/span><\/span>\n<span class=\"l\">    },<\/span>\n<span class=\"l\">    <span class=\"n\">\"node_modules\/semver\"<\/span>: {<\/span>\n<span class=\"l\">      <span class=\"n\">\"version\"<\/span>: <span class=\"s\">\"7.8.6\"<\/span>,<\/span>\n<span class=\"l\">      <span class=\"n\">\"dev\"<\/span>: <span class=\"kc\">true<\/span>,<\/span>\n<span class=\"l\">      <span class=\"n\">\"license\"<\/span>: <span class=\"s\">\"ISC\"<\/span><\/span>\n<span class=\"l\">    }<\/span>\n<span class=\"l\">  }<\/span>\n<span class=\"l\">}<\/span><\/code><\/pre>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 19, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JSON<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">A shortened view of the real lock file. The integrity hash is cut for space.<\/p>\n<ul>\n<li><strong>Always commit <code>package-lock.json<\/code><\/strong> to Git. Never edit it by hand.<\/li>\n<li><code>npm install<\/code> may update the lock file when <code>package.json<\/code> changes.<\/li>\n<li><code>npm ci<\/code> (\u201cclean install\u201d) deletes <code>node_modules<\/code> and installs <em>exactly<\/em> what the lock file says. It fails if the two files do not match. Use it in CI pipelines and on servers. Our <a href=\"https:\/\/devdojo.co.in\/?p=176\">GitHub Actions CI\/CD for Node.js guide<\/a> uses it in every workflow.<\/li>\n<\/ul>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># fresh, exact install from package-lock.json<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm ci<\/span>\n<span class=\"l\">added 2 packages, and audited 3 packages in 475ms<\/span>\n<span class=\"l\"><\/span>\n<span class=\"l\">found 0 vulnerabilities<\/span>\n<span class=\"l\"><span class=\"c\"># production server: skip devDependencies<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm ci --omit=dev<\/span><\/code><\/pre>\n<\/div>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"scripts\">npm scripts: start, dev and test<\/h2>\n<p>Instead of remembering long commands, put them in the <code>\"scripts\"<\/code> section of <code>package.json<\/code>. Here is our finished file with four scripts:<\/p>\n<div class=\"dd-vsc\" role=\"group\" aria-label=\"Code editor: package.json\">\n<input type=\"radio\" name=\"v5\" id=\"v5f1\" class=\"f1\" checked>\n<input type=\"checkbox\" id=\"v5r1\" class=\"r1\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">package.json \u2014 my-first-npm-app \u2014 Visual Studio Code<\/span><\/div>\n<div class=\"dd-vsc-tabs\">\n<label for=\"v5f1\" class=\"t1\"><b class=\"ic json\">{}<\/b>package.json<\/label>\n<label for=\"v5r1\" class=\"run run1\" title=\"Show the output in the terminal\">\u25b6 Run<\/label>\n<\/div>\n<div class=\"dd-vsc-pane p1\">\n<div class=\"dd-vsc-crumbs\">my-first-npm-app \u203a package.json<\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\">{<\/span>\n<span class=\"l\">  <span class=\"n\">\"name\"<\/span>: <span class=\"s\">\"my-first-npm-app\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"version\"<\/span>: <span class=\"s\">\"1.0.0\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"description\"<\/span>: <span class=\"s\">\"\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"scripts\"<\/span>: {<\/span>\n<span class=\"l\">    <span class=\"n\">\"test\"<\/span>: <span class=\"s\">\"node --test\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">\"start\"<\/span>: <span class=\"s\">\"node app.js\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">\"dev\"<\/span>: <span class=\"s\">\"node --watch app.js\"<\/span>,<\/span>\n<span class=\"l\">    <span class=\"n\">\"versions\"<\/span>: <span class=\"s\">\"node versions.js\"<\/span><\/span>\n<span class=\"l\">  },<\/span>\n<span class=\"l\">  <span class=\"n\">\"keywords\"<\/span>: [],<\/span>\n<span class=\"l\">  <span class=\"n\">\"author\"<\/span>: <span class=\"s\">\"\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"license\"<\/span>: <span class=\"s\">\"ISC\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"type\"<\/span>: <span class=\"s\">\"module\"<\/span>,<\/span>\n<span class=\"l\">  <span class=\"n\">\"dependencies\"<\/span>: {<\/span>\n<span class=\"l\">    <span class=\"n\">\"dayjs\"<\/span>: <span class=\"s\">\"^1.11.23\"<\/span><\/span>\n<span class=\"l\">  },<\/span>\n<span class=\"l\">  <span class=\"n\">\"devDependencies\"<\/span>: {<\/span>\n<span class=\"l\">    <span class=\"n\">\"semver\"<\/span>: <span class=\"s\">\"^7.8.6\"<\/span><\/span>\n<span class=\"l\">  }<\/span>\n<span class=\"l\">}<\/span><\/code><\/pre>\n<div class=\"dd-vsc-term\"><div class=\"dd-term-head\"><span>TERMINAL<\/span><span>OUTPUT<\/span><span>PROBLEMS<\/span><span class=\"dd-term-note\">Real output (Node.js 22, npm, Linux)<\/span><\/div><pre><code><span class=\"gp\">$<\/span> npm start\n&gt; my-first-npm-app@1.0.0 start\n&gt; node app.js\n\nLaunch date: 25 Dec 2026\nDays to go: 49\nOne week later: Friday, 13 November<\/code><\/pre><\/div>\n<div class=\"dd-vsc-status\"><span>\u2387 main<\/span><span>Ln 21, Col 1<\/span><span class=\"sp\"><\/span><span>Spaces: 2<\/span><span>UTF-8<\/span><span>LF<\/span><span>JSON<\/span><\/div>\n<\/div>\n<\/div>\n<p class=\"dd-vsc-hint\">Click <strong>\u25b6 Run<\/strong> to run <code>npm start<\/code> (real output).<\/p>\n<ul>\n<li><code>npm start<\/code> and <code>npm test<\/code> are special: they work without the word <code>run<\/code>.<\/li>\n<li>Every other script needs <code>npm run<\/code>: <code>npm run dev<\/code>, <code>npm run versions<\/code>.<\/li>\n<li><code>node --watch app.js<\/code> restarts your app every time you save a file. It is built into Node.js, so you no longer need nodemon for simple projects.<\/li>\n<li>Run <code>npm run<\/code> with no name to list every script in the project.<\/li>\n<\/ul>\n<p>You can also set scripts from the terminal with <code>npm pkg set<\/code>:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"gp\">$<\/span> npm pkg set scripts.dev=\"node --watch app.js\"<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm run<\/span>\n<span class=\"l\">Lifecycle scripts included in my-first-npm-app@1.0.0:<\/span>\n<span class=\"l\">  test<\/span>\n<span class=\"l\">    node --test<\/span>\n<span class=\"l\">  start<\/span>\n<span class=\"l\">    node app.js<\/span>\n<span class=\"l\">available via `npm run-script`:<\/span>\n<span class=\"l\">  dev<\/span>\n<span class=\"l\">    node --watch app.js<\/span>\n<span class=\"l\">  versions<\/span>\n<span class=\"l\">    node versions.js<\/span><\/code><\/pre>\n<\/div>\n\n<h2 id=\"npx\">Running tools with npx<\/h2>\n<p><code>npx<\/code> also comes with npm. It runs a command from a package <strong>without installing it globally<\/strong>. If the package is already in your project, npx uses that copy; otherwise it downloads it to a cache and runs it. Here we use the <code>semver<\/code> command-line tool from our dev dependency:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 my-first-npm-app\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 my-first-npm-app<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># which of these versions match ^1.11.0?<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npx semver -r \"^1.11.0\" 1.10.7 1.11.5 1.12.0 2.0.0<\/span>\n<span class=\"l\">1.11.5<\/span>\n<span class=\"l\">1.12.0<\/span>\n<span class=\"l\"><span class=\"c\"># create projects without global installs (asks before downloading)<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npx create-vite@latest my-react-app<\/span><\/code><\/pre>\n<\/div>\n<div class=\"dd-tip\"><strong>Tip:<\/strong> prefer <code>npx<\/code> and project dev dependencies over <code>npm install -g<\/code>. Global packages are shared by all projects on your computer, so two projects that need different versions will fight.<\/div>\n\n<h2 id=\"update-remove\">Update, remove and audit packages<\/h2>\n<p>Packages get new versions all the time. These commands keep your project healthy. Here an older project has <code>dayjs<\/code> pinned to 1.11.10:<\/p>\n<div class=\"dd-vsc dd-vsc-termonly\" role=\"group\" aria-label=\"Terminal: Terminal \u2014 old-project\">\n<div class=\"dd-vsc-bar\"><span class=\"dd-dots\"><i><\/i><i><\/i><i><\/i><\/span><span class=\"dd-vsc-title\">Terminal \u2014 old-project<\/span><\/div>\n<pre class=\"dd-vsc-code\"><code><span class=\"l\"><span class=\"c\"># what is out of date?<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm outdated<\/span>\n<span class=\"l\">Package  Current   Wanted   Latest  Location            Depended by<\/span>\n<span class=\"l\">dayjs    1.11.10  1.11.10  1.11.23  node_modules\/dayjs  old<\/span>\n<span class=\"l\"><span class=\"c\"># update within your ranges (the \"Wanted\" column)<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm update<\/span>\n<span class=\"l\"><span class=\"c\"># jump to the newest version, even a new major<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm install dayjs@latest<\/span>\n<span class=\"l\"><span class=\"c\"># remove a package from node_modules and package.json<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm uninstall semver<\/span>\n<span class=\"l\"><span class=\"c\"># check for known security problems<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm audit<\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm audit fix<\/span>\n<span class=\"l\"><span class=\"c\"># see what is installed<\/span><\/span>\n<span class=\"l\"><span class=\"gp\">$<\/span> npm ls<\/span><\/code><\/pre>\n<\/div>\n<p><strong>Current<\/strong> is what you have, <strong>Wanted<\/strong> is the newest version allowed by your range, and <strong>Latest<\/strong> is the newest version on the registry. When Latest is a new <em>major<\/em> version, read the package changelog before upgrading.<\/p>\n\n<h2 id=\"errors\">Common errors and fixes<\/h2>\n<div class=\"dd-tablewrap\"><table>\n<thead><tr><th>Error<\/th><th>Why it happens<\/th><th>Fix<\/th><\/tr><\/thead>\n<tbody>\n<tr><td><code>npm error code ENOENT<\/code> \u2026 <code>Could not read package.json<\/code><\/td><td>You ran npm outside your project folder, or the project has no package.json yet.<\/td><td><code>cd<\/code> into the project folder, or run <code>npm init -y<\/code>.<\/td><\/tr>\n<tr><td><code>ERR_MODULE_NOT_FOUND<\/code>: Cannot find package &#8216;dayjs&#8217;<\/td><td>The package is not installed in this project (or <code>node_modules<\/code> was deleted).<\/td><td>Run <code>npm install<\/code> (or <code>npm install dayjs<\/code>) in the project folder.<\/td><\/tr>\n<tr><td><code>npm error code E404<\/code> \u2026 is not in this registry<\/td><td>Typo in the package name, or the package does not exist.<\/td><td>Check the exact name on npmjs.com and install again.<\/td><\/tr>\n<tr><td><code>npm error Missing script: \"dev\"<\/code><\/td><td>There is no <code>dev<\/code> entry in <code>\"scripts\"<\/code>.<\/td><td>Run <code>npm run<\/code> to list scripts, then add the missing one.<\/td><\/tr>\n<tr><td><code>npm ci<\/code> fails: package.json and package-lock.json are not in sync<\/td><td>Someone changed package.json without updating the lock file.<\/td><td>Run <code>npm install<\/code> locally and commit the updated lock file.<\/td><\/tr>\n<tr><td><code>npm error code ERESOLVE<\/code> unable to resolve dependency tree<\/td><td>Two packages want different versions of the same peer dependency.<\/td><td>Update the older package first; use <code>--legacy-peer-deps<\/code> only as a last resort.<\/td><\/tr>\n<tr><td><code>EACCES: permission denied<\/code> on global install<\/td><td>npm is trying to write to a system folder.<\/td><td>Use npx, or install Node.js with a version manager (nvm, fnm). Do not use sudo.<\/td><\/tr>\n<\/tbody><\/table><\/div>\n<\/div>\n\n\n\n<div class=\"dd-post\">\n<h2 id=\"best-practices\">npm and package.json best practices<\/h2>\n<ol class=\"dd-steps\">\n<li><strong>Commit <code>package.json<\/code> and <code>package-lock.json<\/code>; ignore <code>node_modules<\/code>.<\/strong> Anyone can rebuild <code>node_modules<\/code> with one command.<\/li>\n<li><strong>Use <code>npm ci<\/code> in CI and on servers.<\/strong> It is faster and gives exactly the versions you tested.<\/li>\n<li><strong>Put tools in devDependencies.<\/strong> Production stays smaller, faster to install and safer.<\/li>\n<li><strong>Check a package before installing it:<\/strong> weekly downloads, last publish date, open issues and licence on npmjs.com. Fewer, well-maintained packages mean fewer security problems.<\/li>\n<li><strong>Watch for typos.<\/strong> Attackers publish look-alike names (for example <code>expresss<\/code>). Copy names from the official docs.<\/li>\n<li><strong>Run <code>npm audit<\/code> and <code>npm outdated<\/code> regularly<\/strong>, and update in small steps with your tests running.<\/li>\n<li><strong>Add <code>\"private\": true<\/code> and <code>engines<\/code><\/strong> to app projects so nobody publishes them by mistake and everyone knows the Node.js version.<\/li>\n<\/ol>\n\n<h2 id=\"practice\">Practice task<\/h2>\n<p>Build a tiny \u201cfestival countdown\u201d app using npm:<\/p>\n<ol>\n<li>Create a folder <code>countdown<\/code>, run <code>npm init -y<\/code> and <code>npm pkg set type=module<\/code>.<\/li>\n<li>Install <code>dayjs<\/code> as a dependency.<\/li>\n<li>Create <code>app.js<\/code> that prints how many days are left until Diwali, New Year and your birthday.<\/li>\n<li>Add scripts: <code>start<\/code> (<code>node app.js<\/code>) and <code>dev<\/code> (<code>node --watch app.js<\/code>).<\/li>\n<li>Delete <code>node_modules<\/code>, run <code>npm ci<\/code>, then <code>npm start<\/code>. It should still work, because the lock file remembers everything.<\/li>\n<li>Bonus: install <code>semver<\/code> as a dev dependency and use <code>npx semver<\/code> to test which versions <code>~1.11.0<\/code> accepts.<\/li>\n<\/ol>\n\n<h2 id=\"faq\">FAQ<\/h2>\n<details><summary>What is the difference between npm and Node.js?<\/summary><p>Node.js runs JavaScript on your computer or server. npm is a separate tool that ships with Node.js and manages the packages your code uses. You run code with <code>node<\/code> and manage packages with <code>npm<\/code>.<\/p><\/details>\n<details><summary>Should I commit package-lock.json to Git?<\/summary><p>Yes, for apps always. It makes every install on every machine use exactly the same versions, so bugs cannot appear just because someone installed a day later.<\/p><\/details>\n<details><summary>What does the ^ symbol mean in package.json?<\/summary><p>The caret allows updates that do not change the first non-zero number. <code>^1.11.0<\/code> allows any 1.x version from 1.11.0 up, but never 2.0.0.<\/p><\/details>\n<details><summary>What is the difference between npm install and npm ci?<\/summary><p><code>npm install<\/code> installs packages and may update the lock file. <code>npm ci<\/code> deletes <code>node_modules<\/code> and installs exactly what <code>package-lock.json<\/code> says, failing if it does not match <code>package.json<\/code>. Use install while developing and ci in pipelines and on servers.<\/p><\/details>\n<details><summary>Should I use npm, pnpm, Yarn or Bun?<\/summary><p>Start with npm: it is built in and every tutorial supports it. pnpm, Yarn and Bun use the same <code>package.json<\/code> and are good choices later for faster installs or monorepos. Pick one per project and do not mix lock files.<\/p><\/details>\n<details><summary>Can I delete the node_modules folder?<\/summary><p>Yes. It is safe to delete at any time. Run <code>npm install<\/code> or <code>npm ci<\/code> to get it back.<\/p><\/details>\n\n<div class=\"dd-next\"><strong>Next part:<\/strong> Node.js Part 4, <em>Working with Files and Folders: the fs and path Modules<\/em>. You will read and write files with <code>fs\/promises<\/code>, build safe paths with <code>path<\/code>, list folders and handle file errors the right way.<\/div>\n\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>You now know how <strong>npm and package.json<\/strong> work together. npm downloads packages from the registry into <code>node_modules<\/code>; <code>package.json<\/code> lists what your project needs and the scripts it runs; <code>package-lock.json<\/code> remembers the exact versions. You can tell <strong>dependencies<\/strong> from <strong>devDependencies<\/strong>, read version ranges like <code>^<\/code> and <code>~<\/code>, use <code>npm ci<\/code> for reliable installs, run tools with <code>npx<\/code> and keep packages updated and safe. These skills are used in every Node.js project you will build in the rest of this series.<\/p>\n\n<div class=\"dd-cta\">\n<h3>New posts every day on DevDojo<\/h3>\n<p>Follow the full <strong>Node.js series<\/strong>, from your first script to a production-ready API. Bookmark <a href=\"https:\/\/devdojo.co.in\/\">devdojo.co.in<\/a> and come back for the next lesson.<\/p>\n<\/div>\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.<\/p>\n","protected":false},"author":1,"featured_media":295,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,8],"tags":[43,127,158,159,160,126],"class_list":["post-296","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-backend","category-nodejs","tag-node-js","tag-node-js-for-beginners","tag-npm","tag-package-json","tag-semantic-versioning","tag-series-node-js"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.4 - aioseo.com -->\n\t<meta name=\"description\" content=\"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Lokendra\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/\" \/>\n\t\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.4\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"DevDojo - Empowering Developers\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"npm and package.json Explained | Node.js Part 3\" \/>\n\t\t<meta property=\"og:description\" content=\"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2026-11-06T13:58:46+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2026-11-06T13:58:47+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"npm and package.json Explained | Node.js Part 3\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#blogposting\",\"name\":\"npm and package.json Explained | Node.js Part 3\",\"headline\":\"Node.js Part 3: npm and package.json: Installing and Managing Packages\",\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/nodejs-series-part-3-npm-package-json.jpg\",\"width\":1200,\"height\":630,\"caption\":\"Node.js Part 3 banner: npm and package.json, installing and managing packages\"},\"datePublished\":\"2026-11-06T13:58:46+00:00\",\"dateModified\":\"2026-11-06T13:58:47+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#webpage\"},\"articleSection\":\"Backend, NodeJS, Node.js, Node.js for Beginners, npm, package.json, Semantic Versioning, Series: Node.js\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/#listItem\",\"name\":\"Backend\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/#listItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/nodejs\\\/#listItem\",\"name\":\"NodeJS\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/nodejs\\\/#listItem\",\"position\":3,\"name\":\"NodeJS\",\"item\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/nodejs\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#listItem\",\"name\":\"Node.js Part 3: npm and package.json: Installing and Managing Packages\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/#listItem\",\"name\":\"Backend\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#listItem\",\"position\":4,\"name\":\"Node.js Part 3: npm and package.json: Installing and Managing Packages\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/category\\\/backend\\\/nodejs\\\/#listItem\",\"name\":\"NodeJS\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/\",\"name\":\"Lokendra\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Lokendra\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#webpage\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/\",\"name\":\"npm and package.json Explained | Node.js Part 3\",\"description\":\"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/author\\\/lokendra\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/wp-content\\\/uploads\\\/2026\\\/11\\\/nodejs-series-part-3-npm-package-json.jpg\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#mainImage\",\"width\":1200,\"height\":630,\"caption\":\"Node.js Part 3 banner: npm and package.json, installing and managing packages\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/index.php\\\/2026\\\/11\\\/06\\\/nodejs-series-part-3-npm-package-json\\\/#mainImage\"},\"datePublished\":\"2026-11-06T13:58:46+00:00\",\"dateModified\":\"2026-11-06T13:58:47+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#website\",\"url\":\"https:\\\/\\\/devdojo.co.in\\\/\",\"name\":\"DevDojo\",\"description\":\"Empowering Developers\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/devdojo.co.in\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"npm and package.json Explained | Node.js Part 3","description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.","canonical_url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#blogposting","name":"npm and package.json Explained | Node.js Part 3","headline":"Node.js Part 3: npm and package.json: Installing and Managing Packages","author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/nodejs-series-part-3-npm-package-json.jpg","width":1200,"height":630,"caption":"Node.js Part 3 banner: npm and package.json, installing and managing packages"},"datePublished":"2026-11-06T13:58:46+00:00","dateModified":"2026-11-06T13:58:47+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#webpage"},"isPartOf":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#webpage"},"articleSection":"Backend, NodeJS, Node.js, Node.js for Beginners, npm, package.json, Semantic Versioning, Series: Node.js"},{"@type":"BreadcrumbList","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","position":1,"name":"Home","item":"https:\/\/devdojo.co.in\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/#listItem","name":"Backend"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/#listItem","position":2,"name":"Backend","item":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/#listItem","name":"NodeJS"},"previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/#listItem","position":3,"name":"NodeJS","item":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/","nextItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#listItem","name":"Node.js Part 3: npm and package.json: Installing and Managing Packages"},"previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/#listItem","name":"Backend"}},{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#listItem","position":4,"name":"Node.js Part 3: npm and package.json: Installing and Managing Packages","previousItem":{"@type":"ListItem","@id":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/#listItem","name":"NodeJS"}}]},{"@type":"Organization","@id":"https:\/\/devdojo.co.in\/#organization","name":"DevDojo","description":"Empowering Developers","url":"https:\/\/devdojo.co.in\/"},{"@type":"Person","@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author","url":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/","name":"Lokendra","image":{"@type":"ImageObject","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/99f102f0cc9080237ce54b91304fd1b3b6fa29925cbaeba93cd796872e58b45c?s=96&d=mm&r=g","width":96,"height":96,"caption":"Lokendra"}},{"@type":"WebPage","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#webpage","url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/","name":"npm and package.json Explained | Node.js Part 3","description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/devdojo.co.in\/#website"},"breadcrumb":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#breadcrumblist"},"author":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"creator":{"@id":"https:\/\/devdojo.co.in\/index.php\/author\/lokendra\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/devdojo.co.in\/wp-content\/uploads\/2026\/11\/nodejs-series-part-3-npm-package-json.jpg","@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#mainImage","width":1200,"height":630,"caption":"Node.js Part 3 banner: npm and package.json, installing and managing packages"},"primaryImageOfPage":{"@id":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/#mainImage"},"datePublished":"2026-11-06T13:58:46+00:00","dateModified":"2026-11-06T13:58:47+00:00"},{"@type":"WebSite","@id":"https:\/\/devdojo.co.in\/#website","url":"https:\/\/devdojo.co.in\/","name":"DevDojo","description":"Empowering Developers","inLanguage":"en-US","publisher":{"@id":"https:\/\/devdojo.co.in\/#organization"}}]},"og:locale":"en_US","og:site_name":"DevDojo - Empowering Developers","og:type":"article","og:title":"npm and package.json Explained | Node.js Part 3","og:description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.","og:url":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/","article:published_time":"2026-11-06T13:58:46+00:00","article:modified_time":"2026-11-06T13:58:47+00:00","twitter:card":"summary_large_image","twitter:title":"npm and package.json Explained | Node.js Part 3","twitter:description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts."},"aioseo_meta_data":{"post_id":"296","title":"npm and package.json Explained | Node.js Part 3","description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.","keywords":null,"keyphrases":{"focus":{"keyphrase":"npm and package.json","score":76},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":"npm and package.json Explained | Node.js Part 3","og_description":"Learn npm and package.json step by step: install packages, dependencies vs devDependencies, ^ and ~ version ranges, package-lock.json, npm ci and npm scripts.","og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":0,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":{"faqs":[],"keyPoints":[],"schemas":[],"titles":[],"descriptions":[],"socialPosts":{"email":{"subject":"","preview":"","content":""},"linkedin":[],"twitter":[],"facebook":[],"instagram":[]}},"created":"2026-11-06 12:59:22","updated":"2026-11-06 13:58:47","focus_keyword":"npm and package.json","additional_keywords":null,"truseo_locale":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/index.php\/category\/backend\/\" title=\"Backend\">Backend<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/\" title=\"NodeJS\">NodeJS<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">\u00bb<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tNode.js Part 3: npm and package.json: Installing and Managing Packages\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/devdojo.co.in\/"},{"label":"Backend","link":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/"},{"label":"NodeJS","link":"https:\/\/devdojo.co.in\/index.php\/category\/backend\/nodejs\/"},{"label":"Node.js Part 3: npm and package.json: Installing and Managing Packages","link":"https:\/\/devdojo.co.in\/index.php\/2026\/11\/06\/nodejs-series-part-3-npm-package-json\/"}],"_links":{"self":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/296","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/comments?post=296"}],"version-history":[{"count":1,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions"}],"predecessor-version":[{"id":298,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/posts\/296\/revisions\/298"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media\/295"}],"wp:attachment":[{"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/media?parent=296"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/categories?post=296"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devdojo.co.in\/index.php\/wp-json\/wp\/v2\/tags?post=296"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}