-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfs.js
More file actions
30 lines (23 loc) · 794 Bytes
/
Copy pathfs.js
File metadata and controls
30 lines (23 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require("fs");
const path = require("path");
const os = require("os");
const http = require("http")
//write a file
fs.writeFileSync("message.txt", "Hello Forsyth, Welcome to nodejs!");
console.log("file created succefully");
const content = fs.readFileSync("message.txt", "utf-8");
console.log("file content:", content);
//path module
const filePath = path.join(__dirname, "message.txt");
console.log("file path", filePath);
//os module
console.log("OS Type:", os.type());
console.log("Free memory:", os.freemem());
//http module
const server = http.createServer((req, res) => {
res.writeHead(200, { "content-type": text / plain })
res.end("hello from your node.js server!")
});
server.listen(3000, () => {
console.log("server running on http://localhost:3000")
})