WanderLust is a simple accommodation-listings web application built with Node.js, Express, EJS, and MongoDB. It lets visitors browse listings and create, view, edit, and delete them.
- Browse all listings and view an individual listing
- Create, edit, and delete listings
- Store listing data in MongoDB with Mongoose
- Render pages with EJS and shared layouts
- Use a default placeholder image when a listing has no image URL
- Node.js m express and npm
- MongoDB, running locally or available through a MongoDB connection URI
-
Install the dependencies:
npm install
-
Start MongoDB locally, or set
MONGO_URIto your MongoDB connection URI. If unset, the app connects to:mongodb://127.0.0.1:27017/wanderlustIn PowerShell, for example:
$env:MONGO_URI = "mongodb://127.0.0.1:27017/wanderlust"
-
Start the application from the project directory:
node app.js
The server listens on port
8080by default. Set thePORTenvironment variable to use another port. -
Open http://localhost:8080 in your browser. Visit
/listingsto browse the listings.
| Method | Path | Description |
|---|---|---|
GET |
/ |
Home route |
GET |
/listings |
Show all listings |
GET |
/listings/new |
Show the create-listing form |
POST |
/listings |
Create a listing |
GET |
/listings/:id |
Show a listing |
GET |
/listings/:id/edit |
Show the edit form |
PUT |
/listings/:id |
Update a listing |
DELETE |
/listings/:id |
Delete a listing |
The edit and delete forms use method-override to submit PUT and DELETE requests from HTML forms.
Listings include a title, description, image URL, price, location, and country. The title and price are required. The image URL defaults to a placeholder if none is supplied.
To populate the database with the sample listings in init/data.js, run:
node init/index.jsWarning: The seed script deletes all existing listings in the selected database before inserting the sample data. Set MONGO_URI first if you intend to seed a different database.
app.js Express application and routes
models/listings.js Mongoose listing model
init/ Sample data and database seeding script
views/ EJS pages, layouts, and shared includes
public/ Stylesheets and image assets