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
  • YARN 🧶
  • Architecture and Concepts 🏗️
  • YARN Architecture Diagram 📊
  • Common YARN Commands 🖥️
  • Code Snippets 💻
  • Deployment Commands 🚀
  • Conclusion 🎉

Was this helpful?

  1. experience
  2. Packege Mangers

Yarn

YARN 🧶

YARN is a fast, reliable, and secure dependency management tool for Node.js. It was developed by Facebook in 2016 as an alternative to npm (Node Package Manager).

Architecture and Concepts 🏗️

YARN's architecture is designed for efficiency and reliability:

  • 📁 Workspace: The root directory of your project

  • 📄 package.json: Defines project dependencies and scripts

  • 🔒 yarn.lock: Ensures consistent installs across machines

  • 📦 node_modules: Directory where packages are installed

  • 🌐 Registry: Default is npm registry, but can be changed

Key Concepts:

  • 🔄 Offline Mode: Install packages without internet connection

  • 🚀 Parallel Installation: Faster package installations

  • 🔍 Flat Mode: Resolves version conflicts efficiently

  • 🔐 Checksums: Verifies integrity of installed packages

YARN Architecture Diagram 📊

Common YARN Commands 🖥️

Installation:

npm install -g yarn

Initialize a new project:

yarn init

Add a dependency:

yarn add [package-name]
yarn add [package-name]@[version]
yarn add [package-name] --dev

Remove a dependency:

yarn remove [package-name]

Install all dependencies:

yarn install

Run a script:

yarn run [script-name]

Upgrade packages:

yarn upgrade
yarn upgrade [package-name]
yarn upgrade [package-name]@[version]

Code Snippets 💻

Example package.json:

{
  "name": "my-project",
  "version": "1.0.0",
  "dependencies": {
    "express": "^4.17.1"
  },
  "devDependencies": {
    "jest": "^27.0.6"
  },
  "scripts": {
    "start": "node index.js",
    "test": "jest"
  }
}

Example JavaScript file (index.js):

const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello World!');
});

app.listen(port, () => {
  console.log(`Example app listening at <http://localhost>:${port}`);
});

Running the application:

yarn start

Output:

Example app listening at <http://localhost:3000>

Deployment Commands 🚀

Deployment commands may vary depending on your hosting platform. Here are some general examples:

Build for production:

yarn build

Run tests before deployment:

yarn test

Start in production mode:

yarn start:prod

Remember to add these scripts to your package.json file:

{
  "scripts": {
    "build": "your-build-command",
    "test": "jest",
    "start:prod": "NODE_ENV=production node index.js"
  }
}

Conclusion 🎉

YARN is a powerful and efficient package manager for Node.js projects. Its architecture and features make it a popular choice for many developers. By understanding its concepts and commands, you can streamline your development process and manage dependencies more effectively.

PreviousNPM-Node Packege ManagerNextYarn 2 (Berry)

Last updated 8 months ago

Was this helpful?