Skip to content

ProfessorSolo/Node2Know-ExpressResponseBasics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node2Know — Express Response Basics

A minimal Express app demonstrating two core response methods:

  • res.send() — the generalist (HTML, text, etc.)
  • res.json() — the specialist (APIs)

✅ Prereqs

  • Node.js
  • npm

Check:

node -v
npm -v

📦 Install

npm install

▶️ Run

npm start

🧪 Try it

1) res.send() (HTML)

Open:

  • http://localhost:3000/

You’ll get an HTML response (and your browser will render it).

2) res.json() (API response)

Open:

  • http://localhost:3000/data

You’ll get JSON:

{ "status": "loaded", "cargo": ["box1", "box2"] }

👀 Watch mode

npm run watch

Stop with:

  • Ctrl + C

🧠 Key idea

res.send()

  • flexible: can send HTML, text, buffers, etc.
  • Express will infer a Content-Type (often text/html for strings)

res.json()

  • preferred for APIs
  • sets Content-Type: application/json
  • stringifies objects automatically

📁 Project Structure

.
├── app.js
├── package.json
└── README.md

Repo


License

Node2Know-LEARN-1.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors