Use:
var express = Require ("Express"); var app = Express (); var list = require ("./list.js"); App.get ("/list/:d B", list.handlehttp); var port = n; console.log (port); App.listen (port) ;
List.js:
varSqlite3 = require (' sqlite3 ')). verbose ();vardb =NewSqlite3. Database (' jd.db ');varHandlebars = require (' handlebars '));varFS = require ("FS");functionInidb () {db.serialize (function() { varsql = "CREATE TABLE IF not EXISTS jdbit"SQL+ = "(key text, startdate timestamp, endDate timestamp, type text, source text, name text, recorddate timestamp,"; SQL+ = "Times integer, Endprice integer, Status TEXT, buyer text, PRIMARY key (key ASC)"; Db.run (SQL); varSQL2 = "INSERT into Jdbit (key, name) SELECT ' 1234 ', ' ABCD '"; SQL2+ = "UNION ALL SELECT ' 2 ', ' B '"; SQL2+ = "UNION ALL SELECT ' 3 ', ' C '"; SQL2+ = "UNION ALL SELECT ' 4 ', ' D '"; SQL2+ = "UNION ALL SELECT ' 5 ', ' E '"; SQL2+ = "UNION ALL SELECT ' 6 ', ' F '"; SQL2+ = "UNION ALL SELECT ' 7 ', ' G '"; Db.run (SQL2); });}functionGetjddata (res) {Db.all ("SELECT * from Jdbit",function(err, data) {varhtml = Fs.readfilesync ("web/list.htm", {encoding:"Utf-8" }); varTmpl =handlebars.compile (HTML); varrs =Tmpl (data); Res.end (RS); });} Module.exports={inidb:inidb, handlehttp:function(req, res, next) {if(req.params.db = = "JD") {getjddata (res); } }}
Web/list.htm:
<HTML> <Head></Head> <Body>{{#each this}}<ahref= "/{{key}}"Target= ' _blank '>{{Name}}</a><BR/>{{/each}}</Body></HTML>
Nodejs:express + SQLite + handlebars