0
0
Node.jsframework~20 mins

Built-in modules overview in Node.js - Mini Project: Build & Apply

Choose your learning style9 modes available
Built-in Modules Overview in Node.js
📖 Scenario: You are creating a simple Node.js script to explore some common built-in modules. This will help you understand how to use Node.js features without installing extra packages.
🎯 Goal: Build a Node.js script that imports the fs and path modules, reads the current directory files, and prints their names with their extensions.
📋 What You'll Learn
Import the built-in fs module
Import the built-in path module
Read the list of files in the current directory
Use path.extname to get each file's extension
Print each file name with its extension
💡 Why This Matters
🌍 Real World
Node.js built-in modules let you work with files, paths, and system info without extra installs. This is useful for scripts, servers, and tools.
💼 Career
Understanding built-in modules is essential for Node.js developers to build efficient and maintainable applications.
Progress0 / 4 steps
1
Import the fs module
Write a line to import the built-in Node.js module fs using import fs from 'fs'.
Node.js
Need a hint?

Use the ES module syntax: import fs from 'fs'.

2
Import the path module
Add a line to import the built-in Node.js module path using import path from 'path'.
Node.js
Need a hint?

Use the ES module syntax: import path from 'path'.

3
Read the current directory files
Write a line to read the list of files in the current directory using fs.readdirSync and store it in a variable called files.
Node.js
Need a hint?

Use fs.readdirSync('.') to get files in the current folder.

4
Print each file name with its extension
Write a for...of loop to go through files. Inside the loop, use path.extname(file) to get the extension and print the file name and extension using console.log.
Node.js
Need a hint?

Use a for...of loop and path.extname to get extensions.