//控制台显示 var util = require('util'); var notesdb = require('./notesdb-sqlite3'); // var notesdb = require('./notesdb-mongoose'); notesdb.connect(function(error){ if (error) throw error; }); notesdb.forAll(function(error, row){ util.log('ROW: ' + util.inspect(row)); }, function(error){ if (error) throw error; util.log('ALL DONE'); notesdb.disconnect(function(err){}); });
前台页面在views-sqlite3目录下
layout.html
<!DOCTYPE html> <html> <head> <title><%= title%></title> </head> <body> <h1><%= title%></h1> <p><a href='https://www.jb51.net/view'>View</a> | <a href='https://www.jb51.net/add'>Add</a></p> </body> </html>
viewnotes.html
<% include layout.html %> <table><% notes.forEach(function(note){ %> <tr> <td> <p><%=new Date(note.ts).toString()%>: by <b><%=note.author%></b></p> <p><%=note.note%></p> </td> <td> <form method="get" action="/del"> <input type="submit" value="Delete" /> <input type="hidden" value="<%=note.ts%>" /> </form> <br/> <form method="get" action="/edit"> <input type="submit" value="Edit" /> <input type="hidden" value="<%=note.ts%>" /> </form> </td> </tr> <% }); %> </table>
addedit.html
<% include layout.html %> <form method="post" action="<%=postpath%>"> <% if (note){ %> <input type="hidden" value="<%=note.ts%>" /> <% } %> <input type="text" value="<%=note.author%>" /> <br/> <textarea rows="5" cols="40"> <%=note.note%> </textarea> <br/> <input type="submit" value="Submit" /> </form>
login.html
<% include layout.html %> <form method="POST" action="/login"> <p>Click the <i>Login</i> to log in.</p> <input type="submit" value="Login" /> </form>
node setup.js
node app.js