The command line is more than an old-school tool—it’s a superpower that speeds up everyday developer workflows. Whether you’re creating a new project, installing dependencies, or debugging issues, the terminal gives you control and efficiency. This guide will walk you through terminal basics, show practical examples, and explain how package managers like npm and Yarn help you manage dependencies with confidence.
You’ll learn: navigation and file commands, productivity tips (tab completion, history), core npm and Yarn commands, why package.json matters, common pitfalls, and next steps.
Navigating the Terminal Like a Pro
The terminal (also known as the shell) is a text-based interface for interacting with your computer. Popular shells include Bash, Zsh, and Fish. Below are the commands every beginner should master.
Fundamental file and directory commands
- Print working directory (where you are):
pwd
# /home/you/projects/my-app
- List files & details:
ls(with useful options)
ls -l # long format (permissions, owner, size)
ls -a # show hidden files
- Change directory:
cd
cd src # go into src
cd .. # go up one level
cd ~ # go to your home directory
- Make directory:
mkdir
mkdir my-new-dir
- Create a file:
touch
touch index.js
- Remove files or directories:
rm
rm file.txt # remove a file
rm -r folder/ # remove a directory and its contents
rm -rf dist/ # forced removal (dangerous)
- Move/rename:
mv; Copy:cp
mv temp.txt index.txt # rename
cp -r public/ backup/ # copy directory recursively
Productivity enhancers
- Tab completion: Press Tab while typing a file or command to auto-complete names.
- Command history:
historylists earlier commands;Ctrl+Rtriggers reverse search to find previous commands quickly. - Aliases (config in
~/.bashrcor~/.zshrc):
# Example: add this to ~/.bashrc
alias gs='git status'
alias serve='npm run dev'
- Quick inline editing:
Ctrl+A(jump to start),Ctrl+E(jump to end),Ctrl+U(clear line before cursor).
Use the terminal daily—start with simple file navigation and commands, then build muscle memory for the most common ones.
npm & Yarn: Your JavaScript Package Powerhouses
Modern JavaScript projects rely on packages: modules of code that solve common tasks (testing, routing, UI components). npm (Node Package Manager) and Yarn handle installing, updating, and maintaining these dependencies.
What problem do they solve?
Managing dependencies manually is error-prone: different developers may have different versions of libraries, builds may break, or the same package may be installed multiple times. Package managers solve these problems by:
- Providing a deterministic install using lockfiles (package-lock.json or yarn.lock).
- Installing and resolving dependency trees automatically.
- Running scripts (test, build, start) through a unified API.
A short npm vs Yarn note
- npm is the original package manager for Node.js. Yarn emerged as a faster, more deterministic alternative, introducing
yarn.lock. Both have converged over time regarding features. - Yarn (classic and v2/v3) offers speed and workspace features; npm has improved greatly and remains the default for many projects. Another fast alternative is
pnpm(efficient disk usage via symlinks).
Essential commands (npm & Yarn equivalents)
- Initialize a project
npm init # prompts
npm init -y # create package.json with defaults
# Yarn equivalent
yarn init # prompts
yarn init -y # defaults
- Add a dependency
npm install axios --save
# yarn
yarn add axios
- Install all dependencies (from package.json)
npm install
# yarn
yarn install
- Remove a dependency
npm uninstall lodash
# yarn
yarn remove lodash
- Run scripts from package.json
npm run build
# yarn
yarn run build
# yarn has a shorthand: yarn build
Install devDependencies (tools used for building/testing)
npm install --save-dev jest eslint
# yarn
yarn add --dev jest eslint
These commands are enough to get started. Try creating a new project and installing your first dependency to see the workflow in action.
The Art of Package Management
Package management isn’t just running commands—it’s about collaboration, consistency, and maintaining healthy projects.
package.json — the project manifest
package.json lists project metadata (name, version), dependencies, scripts, and more. It’s the single source of truth for package managers and team collaboration.
{
"name": "my-app",
"version": "1.0.0",
"scripts": {
"start": "node server.js",
"test": "jest"
},
"dependencies": {
"express": "^4.18.2"
}
}
node_modules and .gitignore
node_modules/ stores installed packages and can be quite large. Commit package.json and lockfiles, but add node_modules/ to .gitignore to keep your repository small and portable.
Semantic Versioning (SemVer)
Dependencies use SemVer: MAJOR.MINOR.PATCH. Examples:
^1.2.3— allow updates to MINOR/PATCH but not MAJOR.~1.2.3— allow updates to PATCH only.
Use lockfiles (package-lock.json or yarn.lock) in version control for exact reproducibility across installs.
Common Pitfalls & Best Practices
- Avoid committing
node_modules/—use.gitignore. - Keep
package.jsontidy: separatedependencies(runtime) fromdevDependencies(build/test tools). - Use lockfiles and commit them to version control to avoid ‘works on my machine’ issues.
- Prefer small, single-purpose npm scripts (e.g.,
build,test) and chain them withnpm run. - Understand SemVer before using
^or~so you don’t accidentally introduce incompatible updates. - Use
npx(ornpm exec) to run one-off tools without global installs:npx create-react-app my-app.
Conclusion & Call to Action
The terminal and package managers are core developer tools that increase speed, control, and confidence. Practice the commands above regularly: create a small project, use npm or yarn to install dependencies, experiment with scripts and try git for version control. From there, explore shell scripting, pnpm/bun, and more advanced workflows (workspaces, CI/CD) to become even more effective.
Next steps: create a demo app with npm init, install a package, add a start script, and deploy or run locally. Keep practicing—command-line fluency compounds fast. Happy hacking! 🚀
Further resources
- npm docs
- Yarn docs
- Semantic Versioning specification
- Learn the Command Line (Codecademy)
- Learn Git Branching
Comments