Skip to content

Instantly share code, notes, and snippets.

@Jan-Bart
Created June 5, 2014 20:16
Show Gist options
  • Save Jan-Bart/56743dcf757525c2d3e1 to your computer and use it in GitHub Desktop.
Save Jan-Bart/56743dcf757525c2d3e1 to your computer and use it in GitHub Desktop.
// Require a bunch of shit
var express = require('express');
var app = express();
var mongoose = require('mongoose');
var fs = require('fs');
mongoose.connect('mongodb://localhost/devdocu');
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function callback () {
// yay!
console.log("open");
// Page
var pageFields = {
content: String,
lastmodified: Date,
nicename: String,
path: String,
title: String
};
var pageSchema = mongoose.Schema(pageFields);
var Page = mongoose.model('Page', pageSchema);
Page.find(function (err, pages) {
if (err) return console.error(err);
pages.forEach(function(p){
var content = "/* \n Title: "+p.title+"\n Sort: 2\n */ \n";
content = content + p.content;
fs.writeFile("/Users/jan-bart/Desktop/test/"+p.nicename+".md", content, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
});
})
});
app.get('/', function(req, res){
res.send('hello world');
});
app.listen(3122);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment