Student Activity
Student Activity (30-min)
javascript코드 복사const fs = require('fs'); // Write to a file fs.writeFile('example.txt', 'This is an example file.', (err) => { if (err) throw err; console.log('File created and written to.'); // Read the file fs.readFile('example.txt', 'utf8', (err, data) => { if (err) throw err; console.log('File content:', data); // Append to the file fs.appendFile('example.txt', '\nAppended text.', (err) => { if (err) throw err; console.log('Content appended to file.'); }); }); });bash코드 복사node fileOperations.js
javascript코드 복사const http = require('http'); const server = http.createServer((req, res) => { if (req.url === '/') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Welcome to the Home Page'); } else if (req.url === '/about') { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('This is the About Page'); } else { res.writeHead(404, { 'Content-Type': 'text/plain' }); res.end('404 Not Found'); } }); server.listen(3000, () => { console.log('Server running at http://localhost:3000'); });bash코드 복사node httpServer.js
Last updated