Ankita.eth
GithubContact
  • About Ankita
  • experience
    • TECHNOLOGIES
    • Frontend
      • Javascript
      • React
      • NextJS
      • HTML & CSS
      • UI Libraries & Frameworks
        • Tailwind CSS
        • Comprehensive Guide to UI Libraries and Frameworks
    • Backend
      • Node.js
      • Express.js
    • Database
      • Mongodb, Mongoose
      • PostgresSQl
      • MySQL
    • Packege Mangers
      • NPM-Node Packege Manager
      • Yarn
      • Yarn 2 (Berry)
      • PNPM
      • BUN
      • Commands cheatsheet
    • API Providers
      • Alchemy
      • Telegram Bot
      • CoinMarket
      • Thirdweb
      • Infura
      • Moralis
    • DevOps/Infrastructure
      • Docker
      • Kubernetes
      • CI/CD
      • Docker Swam
    • Protocols
      • ERCs & EIPs
        • ERC-20
        • ERC-721
        • ERC-1155
        • ERC-4337
        • ERC-6551
        • ERC-777
        • ERC-3643
        • EIP-7702
        • ERC-7715
        • ERC-7739
        • EIP-6780
        • EIP-5792
        • ERC-4626
        • EIP-1559
        • ERC-404
        • ERC-3643
        • ERC-223
    • Web3 Toolkits
      • Foundry
      • Hardhat
      • RemixIDE
    • Messaging/Caching
      • Kafka
      • Redis
      • Sendgrid
    • Blockchain
      • Solana
      • Ethereum
      • Polygon & Zero knowldge Proof
      • Bitcoin
      • Solidity
    • Deployment Platforms
      • AWS
      • Vercel
      • Heroku, Render
      • Domain setup
  • SDKs
    • Google Cloud SDK
    • AWS SDK
    • Firebase SDK
  • EOF EVM Object Format
  • Articles
    • Medium Articles
    • 🌐 My Work
  • 📞 Get in Touch
Powered by GitBook
On this page
  • NPM (Node Package Manager)
  • How to Install NPM
  • 🏗️ Architecture and Concepts
  • 🖼️ NPM Architecture Diagram
  • 🛠️ NPM Commands
  • 💻 Code Snippets
  • 🎓 Advanced NPM Skills

Was this helpful?

  1. experience
  2. Packege Mangers

NPM-Node Packege Manager

NPM (Node Package Manager)

NPM (Node Package Manager) is considered to be the largest software registry in the world. It is free, open-source, installed with Node.js, contains packages written in JSON. The main purpose of NPM is to provide automated dependency and package management. Those who use npm say it helps to improve your experience and the overall efficiency of Node.js development by allowing you to install the exact modules you need. The advantages of NPM are:

  • ease of use for developers

  • local package installation which helps save on space

  • helps reduce the development time

That’s pretty much it, it’s very simple and performs its main function – uploading, storing, sharing, reusing software packages.

How to Install NPM

NPM should be automatically installed when you install Node.js. To check is you have Node.js installed, run this command in your terminal:

node -v

If you already have Node.js installed and want to verify whether you also have NPM, run the following command in your terminal:

npm -v

FYI, npm updates happen more frequently than Node.js, and there are many npm versions out there, so you might want to keep your npm up to date, and possibly even update it right after you installed Node.js. To do that, run the following command:

npm install npm@latest -g

It might also be a good idea to use a version manager with your Node.js package, e.g. nodist or NVM.

🏗️ Architecture and Concepts

NPM follows a client-server architecture:

  • 📡 Client: The NPM CLI tool installed on developers' machines

  • 🖥️ Server: The NPM registry, a large public database of JavaScript packages

Key concepts I'm well-versed in:

  • 📁 package.json: The heart of any Node.js project, defining project metadata and dependencies

  • 🔒 package-lock.json: Ensures consistent installs across environments

  • 📦 node_modules: Directory where packages are installed

  • 🌳 Dependency tree: Hierarchical structure of project dependencies

  • 🔄 Semantic Versioning (SemVer): Version number scheme for packages

🖼️ NPM Architecture Diagram

🛠️ NPM Commands

I am proficient in using a wide range of NPM commands for various tasks:

📥 Installation Commands

# Install all dependencies
npm install

# Install a specific package
npm install lodash

# Install as dev dependency
npm install --save-dev jest

# Install globally
npm install -g typescript

# Install specific version
npm install react@17.0.2

📜 Script Commands

I can efficiently manage and use NPM scripts defined in package.json:

{
  "scripts": {
    "start": "node server.js",
    "dev": "next dev",
    "test": "jest",
    "build": "tsc",
    "lint": "eslint .",
    "deploy": "node deploy.js"
  }
}

Running these scripts:

npm run start
npm run dev
npm test
npm run build
npm run lint
npm run deploy

🚀 Other Useful Commands

# Initialize a new project
npm init -y

# Update packages
npm update

# Remove a package
npm uninstall moment

# List installed packages
npm list

# Run security audit
npm audit

# Publish a package
npm publish

💻 Code Snippets

I can effectively use NPM packages in JavaScript/TypeScript projects. Here are some examples:

🧩 Using a third-party package (lodash)

import _ from 'lodash';

const numbers = [1, 2, 3, 4, 5];
const sum = _.sum(numbers);
console.log(`Sum: ${sum}`);

const users = [
  { name: 'John', age: 30 },
  { name: 'Jane', age: 28 },
  { name: 'Bob', age: 35 }
];
const sortedUsers = _.sortBy(users, 'age');
console.log('Sorted users:', sortedUsers);

🛠️ Creating and publishing an NPM package

  1. Create a new directory and initialize:

mkdir my-awesome-package
cd my-awesome-package
npm init -y
  1. Create your main file (index.js):

// index.js
function greet(name) {
  return `Hello, ${name}!`;
}

module.exports = { greet };
  1. Update package.json:

{
  "name": "my-awesome-package",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \\"Error: no test specified\\" && exit 1"
  },
  "keywords": ["greeting", "npm", "package"],
  "author": "Your Name",
  "license": "MIT"
}
  1. Publish the package:

npm login
npm publish

🎓 Advanced NPM Skills

  • 🔍 Troubleshooting dependency conflicts

  • 🔒 Managing package security with npm audit

  • 🚀 Optimizing install times with npm ci

  • 📊 Analyzing package sizes with npm package-size

  • 🔧 Configuring NPM for different environments

My comprehensive understanding of NPM enables me to efficiently manage dependencies, optimize project structures, and streamline development workflows in Node.js environments.

PreviousPackege MangersNextYarn

Last updated 8 months ago

Was this helpful?