Created
June 5, 2014 20:16
-
-
Save Jan-Bart/56743dcf757525c2d3e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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