//nodemon Todo //https://www.section.io/engineering-education/a-raw-nodejs-rest-api-without-frameworks-such-as-express/ var http = require('http'); var sqlite3 = require('sqlite3').verbose(); //var db = new sqlite3.Database('Todo.db'); //db.run("CREATE TABLE IF NOT EXISTS todo (text TEXT)"); //var stmt = db.prepare("INSERT INTO todo VALUES (?)"); //stmt.run('Sample data 1'); //stmt.run('Anoter data 2'); //stmt.finalize(); const hostname = '127.0.0.1'; const port = 3000; var server = http.createServer(function(req, res) { const { headers, method, url } = req; let body = []; req.on('error', (err) => { console.error(err); }).on('data', (chunk) => { body.push(chunk); }).on('end', () => { body = Buffer.concat(body).toString(); console.log('we up here', body); // At this point, we have the headers, method, url and body, and can now // do whatever we need to in order to respond to this request. if(req.url=='/add') { let db = new sqlite3.Database('Todo.db'); let responseBody = 'no ger'; console.log('hi body'+body); text = JSON.parse(body)['text']; // insert one row into the table db.run(`INSERT INTO todo(text) VALUES(?)`, text , function(err) { if (err) { return console.log(err.message); } }); // close the database connection db.close(); } }); var message = ''; if (req.url=='/'){ res.writeHead(200, {'Content-Type': 'text/html'}); message = `