{"id":23408731,"url":"https://github.com/anbuleo/express-crud","last_synced_at":"2026-04-10T01:04:02.368Z","repository":{"id":204225721,"uuid":"711233695","full_name":"anbuleo/express-crud","owner":"anbuleo","description":"express-crud","archived":false,"fork":false,"pushed_at":"2023-11-15T15:53:51.000Z","size":689,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-14T19:52:36.222Z","etag":null,"topics":["controller","crud","expressjs","filter","if-else","json","listen","module","mvc","nodejs","nodemon","params","port","postman","routes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/anbuleo.png","metadata":{"files":{"readme":"readme.txt","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-28T16:01:56.000Z","updated_at":"2023-10-28T16:05:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"513177da-06e5-405f-8a87-dead36a23514","html_url":"https://github.com/anbuleo/express-crud","commit_stats":null,"previous_names":["anbuleo/express-crud"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anbuleo%2Fexpress-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anbuleo%2Fexpress-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anbuleo%2Fexpress-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/anbuleo%2Fexpress-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/anbuleo","download_url":"https://codeload.github.com/anbuleo/express-crud/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247957517,"owners_count":21024713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["controller","crud","expressjs","filter","if-else","json","listen","module","mvc","nodejs","nodemon","params","port","postman","routes"],"created_at":"2024-12-22T15:17:01.214Z","updated_at":"2025-12-30T23:05:16.101Z","avatar_url":"https://github.com/anbuleo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"npm init =\u003e to intiate the package.json \n\nnpm i express\n\nand create file name index.js because(  \"main\": \"index.js\",) file read the default file index.js\n\nto overcome the req (eg.. create , put ,post)  we can call express because in the express already they were written the code in-bulid\n\n\nimport the express\n\nconst express = require('express')  // common js  (or) Add \"type \": \"module\" in package.json  (import express from 'express)  this is es-6\n \nto create the app\n\nconst app = express()  \n\nthe get req to create \n\napp.get('/',(req,res)=\u003e{\n    res.send(`\u003ch1\u003eWelome to Express \u003c/h1\u003e`)\n})\n\nmost common server port is 8000\n\napp.listen(8000,()=\u003econsole.log(\"app is listening to 8000\"))\n\nThen add script in package.json \nFor the default page setup \n\n\"start\" : \"node index.js\"\n\nthen we call the command as \"npm start\"\n\nTO create data and sending by the req what we need by using params\n\nlet coupons = [\n    {\n        name:'winter cold',\n        startDate : '2023-12-1',\n        expiryDate : '-2024-1-1',\n        code: \"WTR-CLD\",\n        offerValue: 100,\n        discount : 10,\n        status : false\n\n    },\n    {\n        name:'Pre Winter',\n        startDate : '2023-10-1',\n        expiryDate : '-2024-11-1',\n        code: \"PREWTR-CLD\",\n        offerValue: 80,\n        discount : 8,\n        status : true\n\n    }\n ]\n\n//To display all the data \n\n app.get('/coupons',(req,res)=\u003e{\n    res.send({\n        message: 'All the data are fetched successfully',\n        coupons\n    })\n })\n\n ## To provide the data by req id \n\n app.get('/coupons/:id',(req,res)=\u003e{\n    // ## get the id by params\n    let id = Number(req.params.id)\n    // ## Writing a contion avoid unwanted id \n    if(id != NaN \u0026\u0026 id\u003ccoupons.length){\n        res.send({\n            message : 'The entered id Data fetched Success'\n            coupons : coupons[id]\n        })\n    }\n    else {\n        res.send({\n            message : \"Invaild Id\"\n        })\n    }\n })\n\n // ## Create a data\n\n To sending data by json method so we want to use \n  \n  app.use(express.json()) //=\u003e this line is compulsary \n\n\n// To create using post method\n\n  app.post('/coupons',(req,res)=\u003e{\n    let newData = req.body  // here what we enter data in postman app body that comes here \n     // we want to filter data\n     let filteredData = coupons.filter((e)=\u003e e.code === data.code)\n\n     // checking the similarity using if condition and then allow or reject we want decide\n     if( filteredData.length ===0 ){\n        coupons.push(data)\n        res.status(201).send({\n            message : \"The data created Success\"\n        })\n     }\n     else {\n        res.status(400).send({\n            message : \"The data is already exist\"\n        })\n     }\n  })\n\n  app.listen(8000,()=\u003econsole.log(\"The server is listen port 8000\"))\n\n  // ## To edit the data by using [put req]\n\n  app.put('/coupons/:id',(req,res)=\u003e{\n    let id = Number(req.params.id)            //geting id from req params\n    if(id != NaN \u0026\u0026 id \u003c coupons.length){     //applying the condition to edit or send error message\n        coupons.splice(id,1,req.body)\n        res.status(200).send({\n            message : \"The coupon was edited Success\"\n        })\n    }\n    else{\n        res.status(400).send({\n            message : \"Invalid Id\"\n        })\n    }\n  })\n\n  // to delete the data using delete method\n\n  app.delete('/coupons/:id',(req,res)=\u003e{\n    let id = Number(req.params.id)\n     if(id !=NaN \u0026\u0026 id \u003c coupons.length){\n        coupons.splice(id,1)\n        res.status(201).send({\n            message : \"Coupons deeleted success\"\n        })\n     }\n     else {\n        res.status(400).send({\n            message : \"Invalid Id\"\n        })\n     }\n })\n\n\nmvc =\u003e model view controller\n\nadding .env to secure our confidential things\n\nnpm i dotenv\n\ncreate the .env file in global\n\nin the .env file no need define variable name for the data\n\nimport the file in index.js\n\ncommand =\u003e  import dotenv from 'dotenv'\n\n//to use that\n\ndotenv.config()\n\nfor access env file data command =\u003e process.env.filename","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanbuleo%2Fexpress-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanbuleo%2Fexpress-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanbuleo%2Fexpress-crud/lists"}