Tell us what’s happening:
No matter what I try, no matter how many posts I’ve read, I cannot get my challenge to pass the Database connection should be present
check (the other test passes).
Note that I’m using the replit.com site to do my challenges, so I’ve also set up the security of the MongoDB to allow for “universal” access until this challenge is complete.
The app appears to run just fine within the replit site, and produces this output:
FCC Advanced Node and Express
Looks like this page is being rendered from Pug into HTML! Hello
Please login
Here’s my code:
"use strict";
require('dotenv').config();
const express = require("express");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
const session = require("express-session");
const passport = require("passport");
const mongo = require('mongodb').MongoClient;
const app = express();
fccTesting(app); //For FCC testing purposes
app.use("/public", express.static(process.cwd() + "/public"));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
fccTesting(app); //For FCC testing purposes
app.set("view engine", "pug");
app.route("/").get((req, res) => {
res.render(process.cwd() + '/views/pug/index', { title: 'Hello', message: 'Please login' });
});
app.use(session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
}));
app.use(passport.initialize());
app.use(passport.session());
mongo.connect(process.env.DATABASE, {useUnifiedTopology: true, useNewUrlParser: true}, function(err, db){
if (err) return console.log(err);
console.log('Successful database connection')
passport.serializeUser(function(user, done){
done(null, user._id);
});
passport.deserializeUser(function(id, done){
db.collection('users').findOne({_id: new ObjectID(id)}, function(err, doc){
if (err) return console.log(err);
done(null, doc);
})
});
app.listen(process.env.PORT || 3000, () => {
console.log("Listening on port " + process.env.PORT);
});
});
Your project link(s) → https://boilerplate-advancednode-1.benmeece.repl.co
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36
.
Challenge: Implement the Serialization of a Passport User
Link to the challenge: