This repository creates a REST API using Node.js, Express.js, and MongoDB for a note-keeping application. The application allows users to perform CRUD operations on notes.
- Each note has: a title, content, a creation date.
- The app implements the following endpoints:
GET /notes
: Retrieve all notes.POST /notes
: Add a new note.DELETE /notes/:id
: Delete a specific note using its ID.PUT /notes/:id
: Update a specific note using its ID.
- The app conects to a MongoDB database and uses Mongoose for object modeling.
- The app handles the potential errors gracefully. If an error occurs, the API returns a suitable status code and a descriptive error message.
- models/noteModel.js
This file defines the Mongoose model for notes. Mongoose is an Object Data Modeling (ODM) library for MongoDB and Node.js. The noteModel
creates a model based on the noteSchema
that represents the structure of the note document within the MongoDB collection.
- routes/notes.js
This file contains all the routes related to notes. Express routers provide a way to group route handlers. The notes.js
router handles routes for retrieving, adding, updating, and deleting notes.
- controllers/noteController.js
The controller file contains the logic for handling requests and responses related to notes. It interacts with the noteModel
to perform CRUD operations on notes.
- index.js
This is the main file of the application and it represents the server itself. It sets up the Express application, connects to the MongoDB database, and defines the routes for the application. The index.js
file also imports and uses the noteController
to handle requests related to notes.
To run this application locally, follow these steps:
-
Clone the repository:
git clone https://github.com/dohmeid/my-note-keeper.git
-
Install the required dependencies
npm i express mongoose npm i --save-dev dotnet nodemon
-
Make sure you have MongoDB installed and running locally.
-
Start the server using:
npm run devStart
or using:
npm start
-
Visit
http://localhost:3000
in your browser to access the application or use REST Client extension in vscode.