27 lines
481 B
JavaScript
27 lines
481 B
JavaScript
const http = require('http');
|
|
const fs = require('fs');
|
|
|
|
const port = 8080;
|
|
|
|
string = "ERROR"
|
|
|
|
fs.readFile('/tmp/test/hello.txt','utf-8', function (err,data) {
|
|
if (err) {
|
|
console.log("Error");
|
|
}
|
|
else
|
|
{
|
|
string = data;
|
|
|
|
}
|
|
|
|
});
|
|
const server = http.createServer((req, res) => {
|
|
res.statusCode = 200;
|
|
res.setHeader('Content-Type', 'text/plain');
|
|
res.end(string);
|
|
});
|
|
|
|
server.listen(port, () => {
|
|
console.log(`Server running at http://127.0.0.1:${port}/`);
|
|
});
|