I just want the word "flower" to show up
I have test terminal for Node and using the preload() and loadJSON(), it work just fine but the word flower not show up, meaning the "js file" does not run on "json file", but the terminal said on console it work for node(meaning it read the json file on terminal)
How do I debug this?
The below is what I use for learning and working on this project >
The Coding Train
10.2: What is JSON? Part I - p5.js Tutorial https://www.youtube.com/watch?v=_NFkzw6oFtQ
8.5: Saving Data to JSON File with Node.js - Programming with Text https://www.youtube.com/watch?v=6iZiqQZBQJY
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sketch</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.sound.min.js"></script>
</head>
<body>
<script src="infoJSON5.js"></script>
</body>
</html>
infoJSON5.js
//var flower;
//function preload() {
// flower = loadJSON("Data3.json")
var fs = require('fs');
var data = fs.readFileSync('Data3.json');
var flower = JSON.parse(data);
console.log(flower);
//}
//Test Terminal
/*
node infoJSON5.js
*/
function setup() {
createCanvas(400, 400);
}
function draw() {
background(0);
fill(flower.r, flower.g, flower.b);
text(flower.name, 10, 50);
}
Data3.json
{
"name":"sunflower",
"r":255,
"g":200,
"b":0
}