Files
LAB4/14/app.js
2023-10-25 09:30:29 +03:00

18 lines
580 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const http = require('http');
const fs = require('fs');
http.createServer(function (request, response) {
console.log(`Запрошенный адрес: ${request.url}`);
// получаем путь после слешаW
const filePath = request.url.substr(1);
fs.readFile(filePath, function (error, data) {
if (error) {
response.statusCode = 404;
response.end('Resourse not found!');
} else {
response.end(data);
}
});W
}).listen(3000, function () {
console.log('Server started at 3000');
});