This is a simple CRUD application for Employee data management using Node.js, Express.js, and MongoDB.
Before you begin, ensure you have met the following requirements:
- Node.js installed on your machine.
- MongoDB installed and running.
- Mongo Shell for interacting with MongoDB.
- Create, Read, Update, and Delete employee records
- Retrieve all employees or a specific employee by ID
- Clone the repository:
git clone https://github.com/dprakash2101/CrudJS.git
- Usage
npm install
- Replace the URL in app.js with your URL in MongoDB.
const express = require('express')
const { default: mongoose } = require('mongoose')
const mangoose = require('mongoose')
const url = 'mongodb://localhost:27017/Employee' //Replace this URL with your connection string
const app= express()
mongoose.connect(url,{useNewUrlParser:true})
const con = mongoose.connection
con.on('open',() => {
console.log('Connected............')
})
app.use(express.json())
const employeesRouter = require('./routes/employees')
app.use('/employees',employeesRouter)
app.listen(9000,() => {
console.log("Server is started.......")
})
- Run: The application will be accessible at http://localhost:9000.
nodemon start
- GET http://localhost:9000/employees/ : Get all employees
- GET http://localhost:9000/employees/:id : Get employee by ID
- POST http://localhost:9000/employees/ : Create a new employee
- PATCH http://localhost:9000/employees/:id : Update employee by ID
- DELETE http://localhost:9000/employees/:id : Delete employee by ID
This project is licensed under the MIT License.
- Devi Prakash
- GitHub: dprakash2101