jotacode.dev

npm commands

Published on
2 min read
npm commands

Frequently Used npm Commands for Local Development

Linking a Local Package

cd ~/path/to/package
npm link

Unlinking a Local Package

cd ~/path/to/package
npm unlink

Removing a Package Globally

npm rm --global <package-name>

Checking if a Package is Removed

npm list --global

Clearing the npx Cache

rm -rf ~/.npm/_npx

Running a Package without Global Installation

npx <package-name>
# add @latest to ensure you're using the latest version
npx <package-name>@latest

Example package.json Configurations for Building a CLI with NodeJS, TypeScript, and esbuild

"scripts": {
    "dev": "tsc -w && npm run link",
    "start": "node dist/index.js",
    "build": "esbuild src/index.ts --bundle --platform=node --target=node18 --outfile=dist/index.js",
    "up": "npm run build && npm publish --access public && npm run unlink",
    "link": "npm unlink your-cli && npm i -g && chmod +x ./dist/index.js && npm link your-cli",
    "unlink": "npm rm -g your-cli && npm unlink your-cli"
  },
"bin": {
  "your-cli": "./dist/index.js"
}
Read More
Routes in Rails

Routes in Rails

Routes in Rails are responsible for mapping URLs to actions in controllers, allowing the framework to know how to respond to different HTTP requests. Routes are defined in the config/routes.rb file and follow a simple yet powerful syntax.