
If you're learning Node.js or working on backend applications, remembering all commands and modules can be difficult.
This Node.js Cheatsheet gives you a quick reference for the most commonly used commands, modules, and patterns developers use daily.
Save this guide for quick access while coding.
1. Check Node & NPM Version
Before starting any project, make sure Node.js and NPM are installed.
node -v
npm -v
2. Initialize a Node Project
Create a new Node.js project.
npm init
Quick setup:
npm init -y
This creates a package.json file.
3. Import & Export Modules
Node.js uses the CommonJS module system.
Import Module
const fs = require("fs");
Export Module
module.exports = myFunction;
4. File System Module
The fs module allows you to work with files.
Read a file:
fs.readFile("file.txt", "utf8", (err, data) => {
console.log(data);
});
Write a file:
fs.writeFile("file.txt", "Hello World", () => {
console.log("File created");
});
Append to a file:
fs.appendFile("file.txt", "More text", () => {
console.log("Data added");
});
5. Create a Simple HTTP Server
You can create a basic web server using the http module.
const http = require("http");
const server = http.createServer((req, res) => {
res.end("Hello World");
});
server.listen(3000);
Run the server:
node app.js
Open in browser:
6. Install Packages with NPM
Install a package:
npm install express
Install globally:
npm install -g nodemon
Remove package:
npm uninstall package-name
7. Async / Await Example
Modern Node.js uses async / await for asynchronous code.
async function getData() {
const data = await fetchData();
console.log(data);
}
8. Useful Developer Tools
Tools commonly used with Node.js:
- Express.js – Web framework
- Nodemon – Auto restart server
- Docker – Containerization
- Git – Version control
Learning **Node.js becomes much easier when you keep a cheatsheet like this nearby.
Use this guide as a quick reference while building backend applications.
If you found this helpful, save it for later and share it with other developers.
For Tutorials: https://www.quipoin.com/tutorial/node-js
Top comments (0)