Code: Select all
<!DOCTYPE html>
<html>
<!-- <body onload="mainline()"> -->
<body>
<button onclick="mainline()">Try</button>
<script>
function mainline() {
window.open("localhost:5000/list");
};
</script>
</body>
</html>
Code: Select all
// Get the required pieces:
const sqlite3 = require('/home/production/node_modules/sqlite3');
var http = require('http');
// Start the HTTP server:
var server = http.createServer(function (req, res) { // 2 - creating server
console.log("request received: " + req.url);
// Put the first screen.
if (req.url === '/list') {
// Open personal database:
let db = new sqlite3.Database('/home/production/personal.db',
sqlite3.OPEN_READWRITE, (err) => {
if (err) {
throw err;
}
});
let sql = 'SELECT description FROM expenses ORDER BY description';
res.writeHead(200, { 'Content-type': 'text/html' });
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
res.write("<p>" + row.description + "</p>");
});
});
// Close the database connection
db.close((err) => { // open for closing
if (err) {
throw err;
}; // end for error
}); // end for closing
}; // end for url='/list'
}); // end for request
server.listen(5000);