This project is a RESTful API built using Node.js, Express.js, and MongoDB. It provides CRUD (Create, Read, Update, Delete) functionality for managing resources. The API follows REST principles and communicates using JSON.
public/: 🖼️ Directory for static files such as CSS, images, etc.style.css: 🎨 CSS file for styling the application.
views/: 📝 Directory containing the EJS templates for rendering HTML views.edit.ejs: 🖋️ EJS template for editing a resource.index.ejs: 📋 EJS template for listing all resources.new.ejs: ➕ EJS template for creating a new resource.show.ejs: 👁️🗨️ EJS template for displaying details of a resource.
index.js: 🚀 The main JavaScript file containing the server logic for the REST API.node_modules/: 📦 Directory containing all the npm packages installed for this project.package.json: 📄 File containing metadata about the project and the list of dependencies.package-lock.json: 🔒 File automatically generated for any operations where npm modifies either thenode_modulestree orpackage.json.
- Install Node.js: Node.js is required to run this project.
- Run
npm installto install all dependencies. - MongoDB Installation Guide: Install and set up MongoDB on your machine.
- Configure the MongoDB connection in
index.js.
- GET /resources:
- Example Response:
[ { "id": 1, "name": "Resource 1", "description": "This is the first resource." }, { "id": 2, "name": "Resource 2", "description": "This is the second resource." } ]
- Example Response:
- GET /resources/:id:
- Example Response:
{ "id": 1, "name": "Resource 1", "description": "This is the first resource." }
- Example Response:
- Clone the repository to your local machine.
- Follow the installation and setup steps above.
- Start the server by running
node index.js. - Use an API testing tool like Postman to interact with the endpoints.
GET /resources: Retrieve all resources.GET /resources/:id: Retrieve a specific resource by ID.POST /resources: Create a new resource.PUT /resources/:id: Update a specific resource by ID.DELETE /resources/:id: Delete a specific resource by ID.
- Node.js
- Express.js
- MongoDB
- EJS: (Embedded JavaScript) for templating
- RESTful API principles
Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.