ik it is i took that after it said mine was working i was just frustrated it wasnt working for two hours and then i checked with theirs and it says not working im getting some time of mongodb is depreciated error
(node:377) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:377) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(node:377) [MONGODB DRIVER] Warning: useNewUrlParser is a deprecated option: useNewUrlParser has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
(Use `node --trace-warnings ...` to show where the warning was created)
(node:377) [MONGODB DRIVER] Warning: useUnifiedTopology is a deprecated option: useUnifiedTopology has no effect since Node.js Driver version 4.0.0 and will be removed in the next major version
Listening on port 8080
Future versions of Node.js will throw an error.
(Use `node --trace-deprecation ...` to show where the warning was created)
Successfully connected to MongoDB.
Hi, I found that you are still struggling with this issue. Sorry if we haven’t answered.
This are the two test:
Database connection should be present.
Waiting:2. Deserialization should now be correctly using the DB and done(null, null) should be called with the doc.
I guess you are not passing even the first one, right? Can you please confirm that? Or are both tests failing? I believe that your connection is ok, @Wrld_runs_on_Code.
We could concentrate on the deserialization, right?
I don’t know if this is nowadays the case but in older versions it was important to put the call of the app.use to initialize passport and the passport.session after the routers and before the server. Maybe it won’t help but could you try that?
Another thing that I would advise is making tests with Postman? You will likely get more information about the success of the connection with that kind of tools. Have a look at your terminal when making those tests?
There are users having similar issues to yours in the forum. I am trying to find one that could help me to give you a tip. I will come back to you as soon as I find one.
"use strict";
require("dotenv").config();
const express = require("express");
const session = require("express-session");
const passport = require("passport");
const { ObjectId } = require("mongodb");
const myDB = require("./connection");
const fccTesting = require("./freeCodeCamp/fcctesting.js");
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 }));
// seeting up the app to use the session
app.use(
session({
secret: process.env.SESSION_SECRET,
resave: true,
saveUninitialized: true,
cookie: { secure: false },
})
);
passport.initialize();
passport.session();
app.set("view engine", "pug");
app.set("views", "./views/pug");
myDB(async (client) => {
const myDataBase = await client.db("freeCodeCamp").collection("users");
// Be sure to change the title
app.route("/").get((req, res) => {
// Change the response to render the Pug template
res.render("index", {
title: "Connected to Database",
message: "Please login",
});
});
// Serialization and deserialization here...
// passort serializeUser and deserializeUser method set-up
passport.serializeUser((user, done) => {
// first argument any error and second id of the user
done(null, user._id);
});
// deserializeUser method
passport.deserializeUser((_id, done) => {
myDataBase.findOne({ _id: new ObjectId(_id) }, (err, doc) => {
// first argument is the error and second argumnet is the full user object in case of deserializeUser.
done(null, doc);
});
});
// Be sure to add this...
}).catch((e) => {
app.route("/").get((req, res) => {
res.render("index", { title: e, message: "Unable to connect to database" });
});
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log("Listening on port " + PORT);
});
this works for me paste the localhost:3000 url in submit option i think it would work