-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial.js
46 lines (35 loc) · 1.08 KB
/
tutorial.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Integrated stuff in node.js
// console
console.log("Console: " + "Hello World!")
// global - allows to create variables that can be accessed from anywhere in the process
global.testvar = "Hello World! Again!"
console.log("Global: " + global.testvar)
// process - gives information about the current process
let processvar = (process.platform)
console.log("Process: " + processvar)
// events
const { EventEmitter } = require("events")
const eventEmitter = new EventEmitter()
// when the event lunch is triggered, the function is executed
eventEmitter.on("lunch", () => {
console.log("Events: Lunch is ready!")
})
// triggering the event
eventEmitter.emit("lunch")
// File System (fs)
// importing methods
const { readFile, readFileSync } = require("fs")
// Syncronous
const txt = readFileSync("./hello.txt", "utf8")
console.log(txt)
// using Callback
readFile("./hello.txt", "utf8", (err, txt) => {
console.log(txt)
})
// async (not working for some reason)
/*
const { readFile } = require("fs").promises
async function hello() {
const file = await readFile("./hello.txt", "uft8")
}
*/