Homework & Coding Practice
Homework/Practice Coding Assignment (20-min)
javascript코드 복사const http = require('http'); const fs = require('fs'); const path = require('path'); const server = http.createServer((req, res) => { const filePath = path.join(__dirname, req.url === '/' ? 'index.html' : req.url); fs.readFile(filePath, (err, data) => { if (err) { res.writeHead(404, { 'Content-Type': 'text/plain' }); return res.end('404 Not Found'); } res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(data); }); }); server.listen(3000, () => { console.log('File server running at http://localhost:3000'); });html코드 복사<h1>Welcome to the Home Page</h1>html코드 복사<h1>About Us</h1>
bash코드 복사node fileServer.js
Expected Outcomes
Last updated