Read a JSON file, transform its data, and write the result to a Markdown file — all using Node.js built-in modules, no npm install needed.
A script that reads students.json and generates a student_report.md file.
node index.jsIf it works, you should see a success message in the terminal and a new student_report.md file appear next to index.js.
| Module | What it does |
|---|---|
fs |
Read and write files on your filesystem |
path |
Build file paths that work on any OS |
Both are built into Node.js — just require them, no install needed.
fs.readFileSync(filePath, 'utf-8')— reads a file and returns its contents as a stringfs.writeFileSync(filePath, content, 'utf-8')— writes a string to a file (creates it if it doesn't exist)JSON.parse(string)— converts a JSON string into a JavaScript objectpath.join(__dirname, 'filename')— builds a safe absolute path relative to the current script
- Require the
fsandpathmodules - Read
students.jsonusingfs.readFileSync - Parse the JSON string into a JavaScript array using
JSON.parse - Build a Markdown string by looping over the students array
- Write the result to
student_report.mdusingfs.writeFileSync
The generated student_report.md should look like this:
# Student Report
Generated on: 20/03/2026
## Summary
Total Students: 3
## Student Details
### Alice Martin
- **Email:** alice.martin@epita.fr
- **Major:** Computer Science
- **GPA:** 3.8
- **ID:** 1
...__dirnameis a Node.js variable that always points to the folder where your script lives — useful for building reliable file pathsArray.forEach()lets you loop over each student and append their info to your Markdown string- Template literals (backticks) make it easy to embed variables inside strings:
`Hello ${name}`