Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam-tiwari-21 committed Jan 26, 2025
0 parents commit 2cee87b
Show file tree
Hide file tree
Showing 20 changed files with 6,465 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.env
node_modules
8 changes: 8 additions & 0 deletions Backend/Model/Todo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import mongoose from "mongoose";
const TodoSchema = new mongoose.Schema({
task: String
})

const TodoModel = mongoose.model("todos", TodoSchema)

export default TodoModel;
32 changes: 32 additions & 0 deletions Backend/Server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import express from 'express';
import cors from "cors";
import mongoose from 'mongoose';
import TodoModel from './Model/Todo.js';
import dotenv from "dotenv";

dotenv.config();

const app = express();
const PORT = process.env.PORT || 3000;

app.use(cors());
app.use(express.json());

mongoose.connect(process.env.MONGO_URI);

app.post("/add",(req,res)=>{
const task = req.body.task;
TodoModel.create({task: task})
.then(result=>res.json(result))
.catch(err=> res.json(err))
})

app.get("/get",(req,res)=>{
TodoModel.find()
.then(result=>res.json(result))
.catch(err=>res.json(err))
})

app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});
Loading

0 comments on commit 2cee87b

Please sign in to comment.