Complete the code to import the built-in 'fs' module in Node.js.
const fs = require([1]);Node.js uses require to import built-in modules like fs for file system operations.
Complete the code to create a simple HTTP server in Node.js.
const http = require('http'); http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World'); }).[1](3000);
The listen method starts the server on the specified port.
Fix the error in the code to read a file asynchronously in Node.js.
const fs = require('fs'); fs.readFile('example.txt', 'utf8', (err, data) => { if (err) throw err; console.log([1]); });
The callback receives the file content as data, which should be logged.
Fill both blanks to export a function named 'greet' in Node.js.
function greet() {
console.log('Hello!');
}
module.[1] = [2];Use module.exports to export the greet function so other files can use it.
Fill all three blanks to create a simple Express server that responds with 'Hi' on the root path.
const express = require([1]); const app = express(); app.[2]('/', (req, res) => { res.[3]('Hi'); }); app.listen(3000);
Import Express with 'express', use get to handle GET requests, and send to send the response.
