NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const express = require("express");
const cors = require("cors");

const app = express();
const port = 4444;

let products = [
{
product_name: "Chips",
prodID: "1",
manu_date: "2021-01-01",
exp_date: "2022-03-01",
price: "$5",
},

{
product_name: "milk",
prodID: "2",
manu_date: "2023-02-01",
exp_date: "2023-02-12",
price: "$2",
},
{
product_name: "cool drink",
prodID: "3",
manu_date: "2022-07-01",
exp_date: "2023-07-01",
price: "$20",
},

{
product_name: "Bread",
prodID: "4",
manu_date: "2023-05-11",
exp_date: "2023-05-01",
price: "$3",
},
{
product_name: "Honey",
prodID: "5",
manu_date: "2022-05-01",
exp_date: "2023-05-01",
price: "$10",
},
{
product_name: "Coffee Powder",
prodID: "6",
manu_date: "2022-05-12",
exp_date: "2023-07-12",
price: "$10",
},
{
product_name: "KIT-KAT",
prodID: "7",
manu_date: "2022-12-20",
exp_date: "2023-05-09",
price: "$3",
},
{
product_name: "Cosmetics",
prodID: "8",
manu_date: "2022-01-20",
exp_date: "2023-02-01",
price: "$50",
},
{
product_name: "ICE-CREAM",
prodID: "9",
manu_date: "2023-01-20",
exp_date: "2023-03-20",
price: "$15",
},
{
product_name: "Milk shake",
prodID: "10",
manu_date: "2023-01-30",
exp_date: "2023-05-30",
price: "$20",
},
{
product_name: "Ghee",
prodID: "11",
manu_date: "2022-02-10",
exp_date: "2025-03-10",
price: "$25",
},
{
product_name: "Biscuit",
prodID: "12",
manu_date: "2023-01-20",
exp_date: "2024-03-20",
price: "$10",
},
// {
// product_name: "Tea Powder",
// prodID: "13",
// exp_date: "2022-05-12",
// manu_date: "2023-07-12",
// price: "$10",
// },
// {
// product_name: "Cosmetics",
// prodID: "14",
// exp_date: "2022-05-12",
// manu_date: "2025-05-02",
// price: "$70",
// },
// {
// product_name: "Spray",
// prodID: "15",
// exp_date: "2022-07-12",
// manu_date: "2025-07-12",
// price: "$50",
// },
];


var productDetails = function (req , res,next) {
res.header ('Access-Control-Allow-Origin','*')
res.header ('Access-Control-Allow-Method','GET,PUT,POST,DELETE')
res.header ('Access-Control-Allow-Header','Context-Type')
next()
}

app.use(cors())

app.use(productDetails)

app.use(express.urlencoded({extended:false}));
app.use(express.json());

app.get('/product',(req,res) => {
res.json(products);
})

app.listen(port, ()=> console.log(`products api listening at port ${port}!`));



app.get('/product/:price' , (req,res) => {
const price = req.params.price;

for (let product of products) {

if (product.price === price) {
res.json(product);
return;
}
}
res.status(404).send('product not found')
})

//post

app.post('/product',(req,res) => {
const product = req.body
products.push(product)
res.send('product is added')
})



//put

app.put('/product/:price' , (req,res) => {
const price = req.params.price;
const newProduct = req.body

for (let i=0; i < products.length; i++) {
let product = products[i]

if (product.price === price) {
products[i] = newProduct;
}
}
res.send('product is edited')
})



app.delete('/product/:price' , (req,res) => {
const price = req.params.price;

products = products.filter(i => {
if(i.price !== price) {
return true;
}
return false;
})
res.send('product is deleted')
})
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.