I'm trying to import the crypto module in a backend node but I am getting the error:
Load of script note "bookmarks" (6OPdoa7YvWok) failed with: Could not find module note crypto⏎
Here is my code:
const {req, res} = api;
const {version} = req.body;
const crypto = require('crypto');
const dataNodeID = await api.currentNote.getRelationValue('data');
const dataNode = await api.getNote(dataNodeID);
const data = await dataNode.getJsonContent();
if (req.method == 'POST' && data.syncID === "")
{
if (version != "1.0.0")
{
res.send(400, "Unexpected version! Expected version \"1.0.0\"");
return;
}
if (data.password === "")
{
//res.send
}
const chars = [..."abcdef0123456789"];
data.syncID = [...Array(32)].map(i=>chars[Math.random()*chars.length|0]).join``;
data.lastUpdate = new Date().toISOString();
dataNode.setJsonContent(data);
res.send({
"version": "1.0.0",
"lastUpdated": data.lastUpdate,
"syncID" : data.syncID});
}
else
{
res.send(400, "SyncID already created! To reset it, delete it in the xBrowserSyncAPI note.");
}
Hello, require function is overriden to work with notes as modules and it currently does not have a fallback for native modules. But that's probably just an omission (not an intention) and I will fix it in the next release.
fixed in stable branch
Most helpful comment
Hello, require function is overriden to work with notes as modules and it currently does not have a fallback for native modules. But that's probably just an omission (not an intention) and I will fix it in the next release.