Node deprecated code and solutions for 2024

This is an update on as much of the changes i had to make to mosh’s course (that I can remember) the course is still good and i can confirm with my deployment. Much of this is discussed in other form posts however much of it I found had also changed as well so i’m just gonna say what worked for me as of April 2024.

Deployment:

Joi Error is objectID is not a function,
solution remove id and replace with .string.hex.length.required
Error joi schema is deprecated
Solution const schema = joi.object also return as shown below there is no

function validateMovie(movie) {
const schema = Joi.object ({
title: Joi.string().min(5).max(50).required(),
genreId: Joi.string().hex().length(24).required(),
numberInStock: Joi.number().min(1).required(),
dailyRentalRate: Joi.number().min(1).required()
});

 return schema.validate(movie); 

}
Joi.validate no longer a function
Solution schema.validate

const result = schema.validate(req.body);
if (result.error) {
res.status(400).send('Validation failed: ’ + result.error.details[0].message)
return;
}

winston Error, with transports, mongoDB(need to pass DB string, this breaks on deployment as you need to pass the environment variable instead of localhost, i remove on deployment pending refactor), and console not logging, (basically everything lol)

solution: fyi this is refactored code for deployment not in index.js

database query logic he says to call Movie.update or remove
solution, if it’s one you must do movie.updateOne or many it’s movie.updateMany, also delete same thing but it’s deleteMany or deleteOne,
also use findByIdAndUpdate and findByIdAndDelete (don’t remember what he uses)

Mongoose Types mosh might have you make a id or auth token like this customerId = mongoose.Types.ObjectId();
Solution: add new in front
customerId = new mongoose.Types.ObjectId();

fawn idk this one id broken as heck no updates in 6 years, i just kept the first solution he showed

I think that’s it as far as i remember please comment if you find anything i missed.

Same for me as well, First Solution is working find, but when try with fawn it throws an error

"
Unhandled rejection MongoError: Unsupported OP_QUERY command: insert. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal

"