Back End Development and APIs Projects - Exercise Tracker

Tell us what’s happening:
I was trying to follow a YouTube video on this after I got stuck. Now, I’m stuck again. I kept getting a deprecation warning message, so I added the following line of code per the suggestion of the compiler:

mongoose.set('strictQuery', false)

Now I’m getting the following error message, and I don’t know how to fix it. Can anyone point me in the right direction? Thx.
Screen Shot 2023-01-24 at 6.21.36 PM

This is all of my code so far:

const express = require('express')
const app = express()
const cors = require('cors')

const mongoose = require('mongoose')
const mySecret = process.env['MONGO_URI']

mongoose.set('strictQuery', false)
mongoose.connect(mySecret, function() {
  console.log("Connected to the database")

const userSchema = mongoose.Schema({
  username: {type: String, unique: true,},

const User = mongoose.model("User", userSchema);

app.use(express.urlencoded({extended: true}))
app.get('/', (req, res) => {
  res.sendFile(__dirname + '/views/index.html')
});'/api/users', async function(req, res) {
  const username = req.body.username;

  const user =  await User.create({

const listener = app.listen(process.env.PORT || 3000, () => {
  console.log('Your app is listening on port ' + listener.address().port)

Your project link(s)

solution: boilerplate-project-exercisetracker - Replit

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Back End Development and APIs Projects - Exercise Tracker

Link to the challenge:

If I fork your code, the single route and DB user creation work for me when using my own DB.

I would use a local setup and see if that helps. Sometimes Replit causes issues.

After it is working locally you can worry about getting it online for the final submission. It might work using Replit again later with a new Replit or using something like Glitch instead.

Just as an aside, if you use unique: true for the Schema you have to handle the case of duplicate user names.

Thank you for the tip about the ‘unique’ parameter. I haven’t used Glitch before … I may try that.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.