-
Initialize Project
npm init -y
- Creates a
package.jsonfile to manage dependencies and scripts.
- Creates a
-
Project Structure
- Created
utils.jsfor utility functions. - Added controller files for handling logic.
- Created
-
Modify
package.json- Updated
package.jsonfor better project organization. add"type": "module",right after"main": "index.js"delete"type": commonjs
- Updated
- Install Nodemon (for auto-restart in development)
npm install -D nodemon --save-dev
- Update
package.jsonto run server in development mode"scripts": { "dev": "nodemon index.js" }
- Run using:
npm run dev
- Run using:
-
Create
.gitignore- Ignore
node_modules,.env, and other unnecessary files.
- Ignore
-
Environment Variables (
.envfile)- Store sensitive configuration data.
-
Handling Requests
- GET, POST, PUT, DELETE requests using built-in
httpmodule.
- GET, POST, PUT, DELETE requests using built-in
-
File System (
fs) Module- Read and write files asynchronously.
const fs = require('fs'); fs.writeFileSync('test.txt', 'Hello, Node.js!');
-
Hashing & Encryption
- Secure data using
cryptomodule.
- Secure data using
-
Operating System (
os) Module- Fetch system details like memory and CPU.
const os = require('os'); console.log(os.platform(), os.freemem());
-
Path Module
- Manage file and directory paths.
const path = require('path'); console.log(path.join(__dirname, 'utils.js'));
-
URL Module
- Parse and manipulate URLs.
const url = require('url'); const myUrl = new URL('https://example.com/path?name=John'); console.log(myUrl.searchParams.get('name'));
-
Events Module
- Handle event-driven programming.
const EventEmitter = require('events'); const emitter = new EventEmitter(); emitter.on('message', () => console.log('Event triggered!')); emitter.emit('message');
-
Process Object
- Access environment variables and process information.
console.log(process.env.PATH);