router.get('/',function(req, res){
// opens the blockly index.html
res.sendFile(path.join(__dirname + '/index.html'));
// query which finds all blocks inside collection
Block.find({}).select('content -_id').exec(function(err, blocks){
if(err){
console.log(err);
}
else {
// iterates through custom blocks in db and shows them in the console
blocks.map(block => {
console.log(block);
//eval(block);
});
}
});
});
The code above is the code that I use for finding my custom blocks in MongoDB. I'm not exactly sure how to use eval() properly.
Coda, when you say "but instead the URL for the src attribute will point to a backend script in your Node.js project" do you mean that in the index.html file where I load Blockly I should write <script src="url of my server and point to the JS script...">? I'm not exactly sure how should I take your advice. I'd be very grateful if you would give me more info about this. I understood it like this: I should point to the script in my project which loads blocks from the database and give it to the html which uses Blockly.
Please correct me if I'm wrong.
Amber, in the code above I'm serving the index.html which loads Blockly and then I'm reading from the database. It could be that I'm missing something or doing something wrong but it still doesn't work the way that I want it to work. I commented eval() out because I tested something.
Thanks again for your time and advice!