npm

npm is a package manager for the JavaScript programming language. It consists of a command line client, and an online database of public and paid-for private packages, called the npm registry.

Perintah Umum

Buat app baru

Nodejs

npx gitignore node
npm init -y

Nextjs

npm init next-app <project_name>

Install dependencies

Jalankan perintah berikut dalam folder app yang sedang aktif.

npm i <package_name>

Cek outdated package

Outdated global

npm outdated -g

Outdated local

npm outdated

Update package

Update global

npm update -g <package_name>

Update local

npm update <package_name>

Build package

Jalankan perintah berikut dalam folder project.

npm run build

Semantic Versioning

npm version major
npm version minor
npm version patch

Publish npm packages

npm login
npm publish

Troubleshooting

Cara mudah update npm di Windows lewat PowerShell

  1. Buka PowerShell dengan opsi Run as Administrator

  2. Ketik Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force

  3. Install package npm-windows-upgrade dengan command,

    npm install --global --production npm-windows-upgrade
    npm-windows-upgrade
  4. Jika ingin langsung mengupgrade, jalankan perintah ini.

    npm-windows-upgrade --npm-version latest

Referensi:

โ€‹