var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var MongoClient = require('mongodb').MongoClient;
app.set('view engine', 'ejs');
app.use("/stylesheets",express.static(__dirname + "/stylesheets"));
app.use(bodyParser());
MongoClient.connect("mongodb://localhost:27017/blog", function(err, db) {
if(!err) {
console.log("We are connected");
db.createCollection('users', function(err, collection) {});
}
});
app.get('/', function(req, res) {
res.render('index')
});
app.post('/send_post', function(req, res) {
var name = req.body.name;
var post_name = req.body.post_name;
var post_text = req.body.post_text;
var collection = MongoClient.Collection('users');
collection.insert({name: "Artem"});
res.send("Name: " + name + ", Name of the post: " + post_name + ", Text of the post:" + post_text);
console.log("Name: " + name + ", Name of the post: " + post_name + ", Text of the post:" + post_text);
});
app.listen(3030);