Node JS

Node js Crud Application Step by Step

this tutorials we are going to teach node js crud application how to do the basic crud operation those are create,update,delete,search,view.

Create the Node Js Project Type on type command prompt

and press enter key.after that you have the fill configation of project.after done stuff you
will get the package.json file.

after that you have to install the following dependencies

  • Express
  • body-parser

After done the stuff you have to create the file server.js

Server.js

inside the project create the folder routes inside the route folder create the page routes.js

routes.js

const express = require('express')
const router = express.Router()

const employee = require('./employee')

router.use('/employee',employee);

module.exports = router

inside the route folder create the file employee

employee

const express = require('express')
const employee = express.Router()
const employeeList = require('./db/employeeList')
const bodyp = require('body-parser')

employee.use(bodyp.json())
employee.use(bodyp.urlencoded({ extended : true}))


employee.get('/', (req, res) => 
{
    if(employeeList)
    {
        res.send(employeeList) 
    }
    else
    {
        res.status(404).send({msg : "Empty List"})
    }

   
})

employee.get('/:id', (req, res) => 
{
 const found = employeeList.some(employee =>  employee.id === parseInt(req.params.id));
 if(found){
     res.send(employeeList.filter(employee =>  employee.id === parseInt(req.params.id)))
 }
 else
 {
     res.status(404).send({msg: `${req.params.id} is not found in employee list`})
 }
})


employee.post('/add', (req, res) => 
{

 const employee = req.body

  if(employee.id && employee.name && employee.address && employee.phone  && employee.active)
  {
      employeeList.push(employee)
      return res.send(employeeList)
  }
  else
  {
      res.status(400).send({msg: `member cannot save`})
  }
})


employee.put('/:id', (req, res) => 
 {

  const updateEmployee = req.body
  const found = employeeList.some(employee =>  employee.id === parseInt(req.params.id));

   if(!found)
   {
     
       return res.status(400).send({msg: `member not found`})
   }   
   if(employee.id && employee.name && employee.address && employee.phone  && employee.active)
   {
    employeeList.push(employee)
       return res.send(employeeList)
   }

   else
   {
    employeeList.forEach(employee =>{
        if(employee.id === parseInt(req.params.id))
        {
            employee.name = updateEmployee.name ? updateEmployee.name : employee.name,
            employee.address = updateEmployee.address ? updateEmployee.address : employee.address,
            employee.phone = updateEmployee.phone ? updateEmployee.phone : employee.phone,
            employee.active = updateEmployee.active ? updateEmployee.active : employee.active
            return res.send(employeeList);

        }
    })
   } 

   res.status(400).send({msg: `employeeList cannot update`})



})


employee.delete('/:id', (req, res) => 
{
    const found = employeeList.some(employee =>  employee.id === parseInt(req.params.id))

  if(found)
  {
    res.send(employeeList.filter(employee =>  employee.id !== parseInt(req.params.id)))

  }
  else
  {
      res.status(400).send({msg: `employee cannot delete`})
  }
})


module.exports = employee

inside the route folder create a folder db inside the folder i created the file employeeList.js

employeeList.js

let employeeList = [

 {
  id : 1,
  name : "raja",
  address : "india",
  phone : 2323232,
  active : true

 },
 {
  id : 2,
  name : "kumar",
  address : "india",
  phone : 4353453,
  active : true

 },
 {
  id : 3,
  name : "nira",
  address : "india",
  phone : 989879,
  active : true

 },
]
module.exports = employeeList

i have attached the video link below. which will do this tutorials step by step.

admin

Recent Posts

Build Simple Water System Calculator in Java Using Swing

If you're just beginning to learn Java GUI programming creating an Water System Calculator is a fantastic project for…

1 week ago

GitHub Copilot vs Microsoft Copilot Best AI Tool to Use in 2025

GitHub is a powerful tool used by teams and developers around the globe. This guide is…

2 weeks ago

Chat with Claude AI Free – Your Super-Smart AI Buddy

It's like having a super-smart buddy that is always there to help you write stories,…

2 weeks ago

Best Festivals UK 2025 [Free Guide Included]

The UK is known for its rich history, diverse culture, and most of all  its…

3 weeks ago

Bank Holidays 2025 UK – Plan Your Perfect Long Weekends

Do you have a plan for your next holiday? Being aware of the Bank Holidays within the…

3 weeks ago

Master Cursor AI Full Guide for Students & Creators

The world is rapidly changing of software development AI-assisted tools for coding have become the main focus. As…

3 weeks ago