fs
) Module Functionsfs.writeFile('/path/to/file', 'Hello World!', err => { if (err) throw err; console.log('The file has been saved!'); });
fs.mkdir('/path/to/directory', { recursive: true }, err => { if (err) throw err; console.log('Directory created successfully'); });`
if (fs.existsSync('/path/to/file')) { console.log('File exists'); } else { console.log('File does not exist'); }
fs.rmdir('/path/to/directory', err => { if (err) throw err; console.log('Directory removed successfully'); });
fs.unlink('/path/to/file', err => { if (err) throw err; console.log('File deleted successfully'); });
const readStream = fs.createReadStream('/path/to/file');
const writeStream = fs.createWriteStream('/path/to/file');
readStream.on('data', chunk => { console.log(chunk); });
readStream.pipe(writeStream);
npm install --save-dev nodemon
Add to package.json
scripts:
"scripts": { "start": "nodemon index.js" }
npm install express
Example usage:
const express = require('express'); const app = express(); app.get('/', (req, res) => res.send('Hello World')); app.listen(3000, () => console.log('Server running on port 3000'));
npm install ejs
Example usage:
app.set('view engine', 'ejs'); app.get('/', (req, res) => res.render('index', { title: 'Home Page' }));
npm install morgan
Example usage:
const morgan = require('morgan'); app.use(morgan('combined'));