This is a Task Manager Application built using Node.js, Express.js, and MongoDB. The application allows users to perform CRUD (Create, Read, Update, Delete) operations on tasks. It is structured as a RESTful API with endpoints for managing tasks.
- Add new tasks.
- Retrieve all tasks or a specific task by ID.
- Update existing tasks.
- Delete tasks.
- Serve static files for the frontend.
├── controllers
│ └── task.js
├── database
│ └── connect.js
├── models
│ └── schema.js
├── node_modules
├── public
│ ├── browser-app.js
│ ├── edit-task.js
│ ├── favicon.ico
│ ├── index.html
│ ├── main.css
│ ├── normalize.css
│ └── task.html
├── routes
│ └── task.js
├── .env
├── .gitignore
├── app.js
├── package-lock.json
└── package.json
Follow these steps to set up the project:
-
Clone the repository:
git clone
-
Navigate to the project directory:
cd -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and add your MongoDB connection string:MONGO_URL= -
Start the application:
npm start
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Fetch all tasks |
| POST | / |
Create a new task |
| GET | /:id |
Fetch a single task by ID |
| PATCH | /:id |
Update a task by ID |
| DELETE | /:id |
Delete a task by ID |
- Node.js: JavaScript runtime for building server-side applications.
- Express.js: Web framework for creating RESTful APIs.
- MongoDB: NoSQL database for storing task data.
- Mongoose: ODM library for MongoDB.
-
Database Connection:
- The
connectDBfunction inconnect.jsestablishes a connection to MongoDB using Mongoose.
- The
-
Schema Definition:
- The
TaskSchemainschema.jsdefines the structure of each task document, including validation rules.
- The
-
Controllers:
- The
task.jsfile contains functions to handle CRUD operations (e.g.,getAllTasks,createTask, etc.).
- The
-
Routes:
- The
routes/task.jsfile maps HTTP methods and endpoints to controller functions.
- The
-
Middleware:
- Static files are served using
app.use(express.static('./public')). - JSON parsing is enabled with
app.use(express.json()).
- Static files are served using
The frontend files are located in the public folder and include HTML, CSS, and JavaScript files for interacting with the API.
The application runs on two ports:
- Port 3000: For serving the backend API.
- Port 4000: For additional server functionality (if needed).
To start the application, use:
npm startYou should see logs indicating that the server is running on both ports.
- Add user authentication and authorization.
- Implement pagination for fetching tasks.
- Enhance frontend design and interactivity.
This project is licensed under the CC0 1.0 Universal (Public Domain Dedication). For more details, visit CC0 1.0 Legal Code.