π§ Step-by-Step Guide to Learn Basic Command Line
β Prerequisites:
- A computer with macOS, Linux, or Windows with WSL (Windows Subsystem for Linux) or Git Bash.
- A terminal app: Terminal (Mac), Bash (Linux), or Git Bash/WSL (Windows).
Step 1: Open the Terminal
-
macOS: Press
Cmd + Space
, typeTerminal
, hit Enter. - Windows: Use Git Bash or WSL.
-
Linux: Press
Ctrl + Alt + T
.
Step 2: Basic Navigation Commands
These help you move around your project folders.
Command | What it does |
---|---|
pwd |
Shows current directory |
ls |
Lists files/folders in a directory |
ls -l |
Lists with details |
cd foldername |
Move into a folder |
cd .. |
Go up one level |
cd |
Go to your home directory |
clear |
Clears the terminal screen |
π Try this:
pwd
ls
cd Desktop
mkdir mern-project
cd mern-project
Step 3: File and Folder Management
Command | What it does |
---|---|
mkdir foldername |
Make a new folder |
touch filename.js |
Create a new file |
rm filename |
Delete a file |
rm -r foldername |
Delete a folder |
code . (if VS Code is installed) |
Open current folder in VS Code |
π Try this:
mkdir backend
cd backend
touch server.js
cd ..
Step 4: Using Package Managers
You'll use Node.js and npm/yarn.
Install Node.js:
Basic npm commands:
Command | What it does |
---|---|
node -v |
Check Node.js version |
npm init -y |
Create a package.json file quickly |
npm install express |
Install Express in your project |
npm install |
Install all dependencies |
npm start |
Run the project (if defined) |
π Try this:
cd backend
npm init -y
npm install express
Step 5: Running Your App
Use Node or tools like nodemon
.
Command | What it does |
---|---|
node server.js |
Runs your Node.js file |
npx nodemon server.js |
Runs and watches for changes |
π Install nodemon
(optional but useful):
npm install --save-dev nodemon
Add this to package.json
:
"scripts": {
"start": "nodemon server.js"
}
Then run:
npm start
Step 6: Git Basics (Optional but recommended)
Command | What it does |
---|---|
git init |
Initialize Git in your folder |
git status |
Show changes |
git add . |
Stage all files |
git commit -m "message" |
Commit with a message |
π Try this:
git init
git add .
git commit -m "initial commit"
Step 7: Bonus - Useful Tips
- Use Tab to autocomplete folder or file names.
- Use β and β arrows to scroll through previous commands.
- Use Ctrl + C to stop running programs.
π§ Cheat Sheet Summary
pwd # where am I?
ls # what's here?
cd folder # go into folder
mkdir folder # make new folder
touch file.js # make new file
npm init -y # init Node project
npm install express # install a package
node file.js # run JS file
code . # open VS Code here
π Printable Command Line Cheat Sheet (Beginner MERN Dev)
You can copy/paste this into a document or print it.
=======================
π§ Basic Terminal Commands
=======================
pwd β Show current directory
ls β List files and folders
ls -l β List with details
cd foldername β Change into a folder
cd .. β Go up one directory
mkdir foldername β Create a new folder
touch filename.js β Create a new file
rm filename β Delete a file
rm -r foldername β Delete a folder
clear β Clear the terminal
code . β Open folder in VS Code
=======================
π¦ Node & npm
=======================
node -v β Show Node.js version
npm init -y β Create package.json
npm install package β Install a package
npm start β Run the app
=======================
π Running a Node App
=======================
node file.js β Run JS file
npx nodemon file.js β Run with auto-restart
npm install --save-dev nodemon β Install nodemon
Add to package.json:
"scripts": {
"start": "nodemon server.js"
}
Then:
npm start
=======================
π± Git Basics
=======================
git init β Start Git repo
git status β Show changes
git add . β Stage all files
git commit -m "msg" β Commit changes
=======================
π‘ Tips
=======================
Tab β Auto-complete filenames
β β β Browse command history
Ctrl + C β Stop running process
β Interactive Command Line Challenge (For Practice)
Try this in your terminal or shell:
- Create a new MERN project folder
cd Desktop
mkdir mern-tutorial
cd mern-tutorial
- Make subfolders
mkdir backend
mkdir frontend
- Initialize a Node project in the backend
cd backend
npm init -y
npm install express
touch server.js
-
Add a basic server
Edit
server.js
(or open in VS Code usingcode .
) and paste:
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/', (req, res) => {
res.send('Hello MERN!');
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
- Run the server
node server.js
- (Optional) Add nodemon
npm install --save-dev nodemon
Update package.json
:
"scripts": {
"start": "nodemon server.js"
}
Run with:
npm start
Top comments (0)