0
0
Expressframework~30 mins

Defining models in Express - Mini Project: Build & Apply

Choose your learning style9 modes available
Defining Models in Express
📋 What You'll Learn
💡 Why This Matters
🌍 Real World
Models help organize and validate data in web apps like Express, making code easier to manage and reuse.
💼 Career
Understanding how to define and export models is essential for backend developers working with Node.js and Express.
Progress0 / 4 steps
1
Create the book model object
Create a JavaScript object called book with these exact properties and values: title set to "The Great Gatsby", author set to "F. Scott Fitzgerald", and year set to 1925.
Express
Need a hint?

Use const book = {} and add the properties inside the curly braces.

2
Add a minimum year variable
Add a variable called minYear and set it to 1900.
Express
Need a hint?

Use const minYear = 1900; to create the variable.

3
Create a validation function
Create a function called isValidBook that takes a parameter book and returns true if book.year is greater than or equal to minYear, otherwise returns false.
Express
Need a hint?

Define the function with function isValidBook(book) {} and use a return statement to compare book.year with minYear.

4
Export the model and function
Export the book object and isValidBook function using module.exports as an object with keys book and isValidBook.
Express
Need a hint?

Use module.exports = { book, isValidBook }; to export both.