Skip to main content

Search stories

No stories found. Try another word.

Tech

Essential Web Developer Commands: Node.js, NPM, Yarn, PHP, Composer & WP-CLI Cheat Sheet

Muhammad Fikri Gunawan · · 7 min read
Essential Web Developer Commands: Node.js, NPM, Yarn, PHP, Composer & WP-CLI Cheat Sheet
Photo: Tirza van Dijk, CC0, via Wikimedia Commons

A practical cheat sheet of the Node.js, NPM, Yarn, PHP, Composer and WP-CLI commands web developers use every day, with what each one does and when to run it.

Short answer: the commands web developers run every day are node -v and npm -v to check your setup, npm install to fetch dependencies, npm run dev and npm run build to run and ship a project, php -S localhost:8000 for a quick PHP server, composer install for PHP packages and wp plugin install <plugin> --activate for WordPress. They are written exactly the same on Linux, macOS, Windows CMD, PowerShell and Git Bash.

This cheat sheet groups those commands by tool, explains what each one does and tells you when to reach for it. Keep it open next to your editor until the commands live in your fingers.

What are Node.js and NPM commands used for?

Node.js is the JavaScript runtime and NPM (Node Package Manager) installs the libraries your project depends on. Almost every modern front-end stack, from Next.js to Vite, is driven through them.

Check your setup

  • node -v: shows the installed Node.js version.
  • npm -v: shows the installed NPM version.

Create a project and add packages

  • npm init -y: creates a default package.json.
  • npm install: installs every dependency listed in package.json.
  • npm install <package>: installs one specific package.
  • npm install <package> --save-dev: installs it as a dev dependency, for tools you only need while building.
  • npm install -g <package>: installs it globally on your system.
  • npm uninstall <package>: removes a package from the project.
  • npm update: updates dependencies to the newest versions your version ranges allow.

Run, build and inspect

  • npm run dev: runs the dev script from package.json, usually a local development server.
  • npm run build: runs the build, normally the production bundle.
  • npm start: runs the start script, commonly the production server.
  • npm list --depth=0: lists the top-level packages installed in the project.
  • npx <package>: runs a package without installing it globally.

Do I need Yarn if I already have NPM?

No. Yarn is an alternative package manager, and NPM is enough for most projects. If a team or repository already uses Yarn, stick with it, because mixing package managers can create conflicting lock files.

  • yarn init -y: creates a new Yarn project.
  • yarn install: installs all dependencies from package.json.
  • yarn add <package>: adds a package.
  • yarn add -D <package>: adds it as a dev dependency.
  • yarn remove <package>: removes a package.
  • yarn dev or yarn build: runs the development or build script.

Which PHP and Composer commands should I know?

PHP ships with its own development server, and Composer is the dependency manager for PHP projects, the equivalent of NPM.

  • php -v: shows the installed PHP version.
  • php -S localhost:8000: starts the built-in local server on port 8000.
  • composer init: creates a new composer.json.
  • composer install: installs every PHP dependency from composer.json.
  • composer require <package>: adds a new PHP package.
  • composer update: updates dependencies to the newest compatible versions.
  • composer dump-autoload: rebuilds the class autoload file, handy after adding new classes.

What can WP-CLI do for a WordPress site?

WP-CLI is the command line interface for WordPress. It lets you install, configure and maintain a site without clicking through the dashboard, which makes migrations and backups much faster.

  • wp --info: shows information about your WP-CLI environment.
  • wp core download: downloads the WordPress core files.
  • wp core install --url=... --title=... --admin_user=... --admin_password=... --admin_email=...: installs WordPress automatically.
  • wp plugin install <plugin> --activate: installs and activates a plugin in one step.
  • wp plugin list: lists installed plugins.
  • wp theme activate <theme>: activates a theme.
  • wp post list: lists posts and pages.
  • wp db export backup.sql: exports a backup of the database.
  • wp db import backup.sql: imports a database from a backup file.
  • wp search-replace "old-domain.com" "new-domain.com": replaces every old URL in the database, which is useful when you migrate a site.
  • wp cache flush: clears the WordPress cache.

Safety tip: run wp db export backup.sql before wp search-replace. A search and replace changes real data, and a backup is the only easy way back.

How do I start a quick local server with Python or open a project in VS Code?

  • python -m http.server 8000: serves the current folder on port 8000. On Linux, macOS and Git Bash you will usually type python3 -m http.server 8000 instead.
  • code .: opens the current folder in Visual Studio Code.

Are these commands the same on Windows, macOS and Linux?

Yes. Node.js, NPM, Yarn, PHP, Composer, WP-CLI and Python are external programs, not part of the operating system shell, so you call them the same way in Linux Terminal, macOS Terminal, Windows Command Prompt, PowerShell and Git Bash. Only the shell commands for files and folders differ between platforms.

Frequently asked questions

What is the difference between npm install and npx?

npm install downloads a package into your project or system so you can keep using it. npx runs a package once without a permanent global installation, which is ideal for project generators and one-off tools.

When should I use --save-dev?

Use it for tools needed only during development, such as linters, test runners and build tools. Runtime libraries your app needs in production stay as normal dependencies.

Is php -S safe for production?

No. The built-in PHP server is meant for local development only. Use a proper web server such as Nginx or Apache for production.

Why use WP-CLI instead of the WordPress dashboard?

It is faster, scriptable and repeatable. You can install plugins, back up the database and move a site to a new domain in seconds, and you can put the same steps in a script to reuse on every project.

Next in this series: Terminal file management in Bash, CMD and PowerShell and the Git and GitHub CLI cheat sheet.