Código
const express = require("express"); const bodyParser = require("body-parser"); const pug = require("pug"); const data = require("mongodb").MongoClient; const app = express(); const mongoose = require('mongoose'); //var model = mongoose.model('algunModelo, algunSchema'); var Schema = mongoose.Schema; var users = Schema({ email: String, password: String }) var db; app.set("view engine", "pug"); app.use(bodyParser.urlencoded({ extended: true })); app.use(express.static("public")); app.use(bodyParser.json()); data .connect("mongodb://localhost:27017/project", (err, database) => { db = database; var user = db.collection("users"); //haciendo referencia a la conexion if (err) return console.log(err); //peticiones HTTP app.get("/", (req, res) => { res.render("index"); console.log("Hiciste una peticion GET"); }); app.get("/register", (req, res) => { res.render("register"); console.log("Entraste al Register"); }); app.post("/home", (req, res) => { console.log("Has accedido al registro"); db.save({ email : req.body.email, password : req.body.password }, err => { if(err) throw err else console.log("Datos enviados \n al servidor"); res.render('home'); }); }); if (err) throw err; else return console.log("Base de datos conectada") }); app.listen(80, "localhost", err => { if (err) throw err; console.log("Ya se conectooooo") });