Skip to content

ProfessorSolo/Node2Know-FileSystemFS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node2Know — File System: fs (Promises)

A minimal Node.js HTTP server that reads HTML partials from disk using the core fs module.

This repo introduces:

  • fs.promises.readFile() (promise-based file I/O)
  • serving HTML from Node’s core http server
  • “partials” (reusable HTML snippets)
  • Promise.all() to load multiple files

✅ Prereqs

  • Node.js installed (includes node)

Verify:

node -v

📄 What's in this repo?

  • server.js — HTTP server that loads partials/header.html and partials/footer.html
  • partials/header.html — reusable header snippet
  • partials/footer.html — reusable footer snippet

▶️ Run the server

From the project folder:

npm run start

You should see:

Server running at http://127.0.0.1:3000/

Then visit:

  • http://127.0.0.1:3000/

If the files load successfully, your terminal will log:

Partials loaded successfully.

👀 Run with watch mode

npm run watch

Now edit partials/header.html or partials/footer.html, save, and refresh your browser to see the change.

Stop the server with:

  • Ctrl + C

🧠 What the code demonstrates

1) Requisition fs.promises

const fs = require("fs").promises;

2) Build file paths using __dirname

const headerPath = __dirname + "/partials/header.html";

__dirname points to the folder containing server.js, which keeps your paths stable even if you run Node from a different working directory.

3) Load multiple files with Promise.all

Promise.all([fs.readFile(headerPath), fs.readFile(footerPath)])
  • Runs both reads at the same time
  • Resolves when both are complete
  • Rejects if either one fails

📁 Project Structure

.
├── package.json
├── server.js
├── partials/
│   ├── header.html
│   └── footer.html
└── README.md

Repo


License

Node2Know-Learn-1.0 (see LICENSE).

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors