Homework & Coding Practice
bash코드 복사node -v npm -v
javascript코드 복사console.log('Start of the program'); setTimeout(() => { console.log('Executed after 2 seconds'); }, 2000); console.log('End of the program');sql코드 복사Start of the program End of the program Executed after 2 seconds
javascript코드 복사const http = require('http'); const server = http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello, Node.js!'); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); });
javascript코드 복사const http = require('http'); const fs = require('fs'); const server = http.createServer((req, res) => { fs.readFile('example.txt', 'utf8', (err, data) => { if (err) { res.writeHead(500, { 'Content-Type': 'text/plain' }); res.end('Error reading file'); return; } res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(data); }); }); server.listen(3000, () => { console.log('Server running at http://localhost:3000/'); });
Expected Outcomes:
Last updated