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.
This is all of my code so far:
const express = require('express')
const app = express()
const cors = require('cors')
require('dotenv').config()
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(cors())
app.use(express.urlencoded({extended: true}))
app.use(express.static('public'))
app.get('/', (req, res) => {
res.sendFile(__dirname + '/views/index.html')
});
app.post('/api/users', async function(req, res) {
const username = req.body.username;
const user = await User.create({
username,
})
res.json(user);
});
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/109.0.0.0 Safari/537.36
Challenge: Back End Development and APIs Projects - Exercise Tracker
Link to the challenge: