Understanding NPM, Packages, Scripts & Node Modules — Simplified for Beginners

Yukti SahuYukti Sahu
4 min read

"If JavaScript is the language, then NPM is your toolkit — and with the right tools, you build anything."

Series

Series: Backend Dev Diaries: JS Edition
Welcome to Part 3 of my backend journey!


🧠 What Is NPM?

NPM stands for Node Package Manager, but here’s the catch — it’s not just about Node.js packages. You’ll find packages for React, Vue, TypeScript, and even tools like Tailwind, ESLint, and more.

Think of NPM as:

A giant supermarket where developers publish and share JavaScript tools (called packages), and we can install them using a simple command.

🧩 In short:

  • Node core modules are already built-in (like fs, http, path)

  • Packages are external tools we install via NPM


🔊 Real-Life Example

Google has a package for Text-to-Speech that lets your app speak out messages. Instead of writing that logic from scratch, you can simply install the package and use it.

npm install @google-cloud/text-to-speech

That's the power of NPM — don’t reinvent the wheel!


🛠 Installing & Uninstalling Packages

You’ll use these NPM commands almost daily:

ActionCommand
Install a packagenpm install <package-name> or npm i <package-name>
Uninstall a packagenpm uninstall <package-name>
Install specific versionnpm i <package-name>@3.1.9

📌 Every package you install is saved as a dependency in your package.json file.


📁 What Is node_modules?

The node_modules folder stores:

  • All the packages you’ve installed

  • Their own dependencies

It's like a warehouse of every Lego piece your project needs — you don’t touch it manually.


📄 Understanding package.json

This file is the heart of your Node project.

It stores:

  • Project metadata

  • Scripts

  • Dependencies (what your project needs to run)

  • DevDependencies (tools used only during development)


⚙️ dependencies vs devDependencies

TypeMeaning
dependenciesRequired for your app to run
devDependenciesOnly needed during development (e.g., nodemon, eslint)

Use the --save-dev flag to install dev tools:

npm install nodemon --save-dev

🔁 Scripts in package.json

Scripts are custom commands you define to automate tasks.

Example "scripts": { "start": "node app.js", "dev": "nodemon app.js", "test": "echo 'Running tests...'", "chacha": "echo 'Yukti is coding...'" }

How to run them:

ScriptCommand
startnpm start
testnpm test
othersnpm run <script-name>

✅ Only start and test can be run without run.

So if you have a script like "chacha", you’ll run:

npm run chacha

🌈 Bonus Tip: Make Your Console Colorful!

Use the chalk package to add colors to your console output ✨

npm i chalk
const chalk = require('chalk');
console.log(chalk.green('Success!'));
console.log(chalk.red.bold('Error!'));

It’s not just fun — colored logs help you debug faster!


📌 Smart Tips from Yukti

  1. ✅ Don’t manually edit node_modules — let npm manage it

  2. 📌 Always commit package.json and .gitignore node_modules

  3. 🧪 Keep devDependencies lightweight for faster builds

  4. 🌍 Use version control with your packages — avoid “works on my machine” bugs

  5. 🔍 Explore npmjs.com to discover powerful tools daily


🙌 Final Thoughts

NPM is not just a tool — it's an ecosystem. Once you understand it deeply, you unlock the full power of modern backend JavaScript development.


🔜 What’s Coming Next

In the next post, we’ll explore:

  • all about express js

Let’s keep growing together 💻✨


💬 Drop a comment if something was confusing — or just to say hi!
📌 Follow me for the next article and backend updates every week.


📦 GitHub Repository

Check out all the code examples, practice scripts, and setups here:
🔗 github.com/yukti-says/Backend-Learning

⭐ Don’t forget to star the repo if you found it helpful!

Yukti Sahu

#JavaScript #Nodejs #Backend #npm #DevDiaries #BeginnerFriendly

20
Subscribe to my newsletter

Read articles from Yukti Sahu directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Yukti Sahu
Yukti Sahu