Skip to content

ProfessorSolo/Node2Know-ExpressLoadAndSendJSON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node2Know — Express Load & Send JSON

A minimal Express app that reads a JSON file from disk and returns it from an API route.

This demo introduces:

  • fs.readFile(...) (callback-style)
  • path.join(...) for safe file paths
  • res.json(...) to return JSON to the client

✅ Prereqs

  • Node.js
  • npm

Check:

node -v
npm -v

📦 Install

npm install

▶️ Run

npm start

🧪 Try it

Home page:

  • http://localhost:3000/

API route:

  • http://localhost:3000/api/inventory

You should receive JSON loaded from:

  • data/inventory.json

👀 Watch mode

npm run watch

Edit data/inventory.json, refresh the /api/inventory route, and you’ll see the updated response.

Stop with:

  • Ctrl + C

🧠 What the route does

  1. Build a file path:
const filePath = path.join(__dirname, "data", "inventory.json");
  1. Read it:
fs.readFile(filePath, "utf8", (err, data) => { ... });
  1. Parse + return:
const inventory = JSON.parse(data);
res.json(inventory);

📁 Project Structure

.
├── app.js
├── package.json
└── data/
    └── inventory.json

Repo


License

Node2Know-LEARN-1.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors