-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNode.js
More file actions
37 lines (31 loc) · 1.39 KB
/
Node.js
File metadata and controls
37 lines (31 loc) · 1.39 KB
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
let url = new URL(window.location.href);
let params = new URLSearchParams(url.search);
let songid = params.get('songId');
console.log(songid);
// To update JSON file
function readTextFile(file, callback) {
var rawFile = new XMLHttpRequest();
rawFile.overrideMimeType("application/json");
rawFile.open("GET", file, true);
rawFile.onreadystatechange = function() {
if (rawFile.readyState === 4 && rawFile.status == "200") {
callback(rawFile.responseText);
}
}
rawFile.send(null);
}
//usage:
readTextFile("./queue.json", function(text){
var data = JSON.parse(text);
console.log(data);
});
// Requiring fs module in which
// writeFile function is defined.
const fs = require('fs');
// Data which will write in a file.
//let data = "Learning how to write in a file."
// Write data in 'Output.txt' .
fs.writeFile('queue.json', data, (err) => {
// In case of a error throw err.
if (err) throw err;
})