从rethinkdb获取条目到node.js博客

我想做一个简单的节点博客,但我需要一些帮助!

我想将我的博客“条目”或“post”保存为rethinkdb,但要做到这一点,我首先需要知道如何让我的post出现在我的博客上,所以我做了一个rethinkdb服务器,有一些条目! 这是它的样子:

[ { "body": "This is the standard hello world message!" , "id": "1" , "published": "2014-04-19" , "title": "Hello World!" } , { "body": "I tought dinner with my family would be horrific, but maybe my low expectations made it bearable" , "id": "3" , "published": "2014-04-19" , "title": "Dinner was ok!" } , { "body": "Here I am ranting about how easter is not as awesome it is said to be" , "id": "2" , "published": "2014-04-19" , "title": "Easter is hard work" } ] 

数据库名称是'blogdb',表名是'entries'

这是我的app.js(node.js服务器)

 /** * Module dependencies. */ var express = require('express'); var routes = require('./routes'); var user = require('./routes/user'); var http = require('http'); var path = require('path'); var app = express(); // all environments app.set('port', process.env.PORT || 3000); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use(express.favicon()); app.use(express.logger('dev')); app.use(express.json()); app.use(express.urlencoded()); app.use(express.methodOverride()); app.use(app.router); app.use(require('stylus').middleware(path.join(__dirname, 'public'))); app.use(express.static(path.join(__dirname, 'public'))); app.use(express.bodyParser()); // development only if ('development' == app.get('env')) { app.use(express.errorHandler()); } app.get('/', function(req, res) { res.render('index', {title: 'My Blog'} ) }); app.get('/about', function(req, res) { res.render('about', { title : 'About' } ) }) app.get('/photos', function(req, res) { res.render('photos', { title : 'Photos' } ) }) http.createServer(app).listen(app.get('port'), function(){ console.log('Express server listening on port ' + app.get('port')); }); 

最后,我们有index.jade(网页)

 extend layout block content p this is where I want my entreis to be! footer p a(href='/') Home | ~ a(href='/about') About Me | ~ a(href='/photos') Some photos 

我知道这不是什么大事,但是在我参加这些活动之前,我并不想做太多的devise。

我必须做什么才能将rethinkdb服务器中的所有条目存入我的网页?

所有的帮助是感谢帮助!

Solutions Collecting From Web of "从rethinkdb获取条目到node.js博客"

我个人使用sailsjs进行节点开发,所以我并不了解具体的expression方式,但…

你需要rethinkdb适配器的初学者…

 var r = require('rethinkdb'); 

那么也许你可以改变你的主页路线这样的事情…

 app.get('/', function(req, res) { r.connect({host: 'rethinkdb_server_ip', db: 'blogdb'}, function(err, conn){ r.table('entries').run(conn, function(err, cursor){ if (err) { //Handle errors if you want. } cursor.toArray(function(entries){ res.render('index', {entries: entries, title: 'My Blog'}) }); }); }); });