I had been working with Espruino for a bit and it is really a wonderful project. But, I am facing an issue for saving the code onto the flash, so that it can still be run when power is supplied to the board(NodeMCU), instead of the PC COM port. The code works completely fine until it is passed from the terminal. But, if I switch over the power supply it stops working. Also, I tried the save() and E.on('init',function(){}) but to no avail. It still doesn't create a web server. If someone could help out here it could be great! Thanks!
function main() {
var http = require('http');
var led = Pin(5);
http.createServer(function (req, res) {
var url = req.url;
res.writeHead(200);
if(url == "/on") {
digitalWrite(led, 1);
res.end("on");
} else if(url == "/off") {
digitalWrite(led, 0);
res.end("off");
} else {
res.end('Lol');
}
}).listen(80);
}
E.on('init', function(){
main();
});
Here's the code I wish to write to my flash for the IOT project I am working on