[go: up one dir, main page]

0% found this document useful (0 votes)
10 views1 page

Notes For React Js App

The document contains a server implementation using Express and Mongoose to manage gift cards. It defines an API endpoint to retrieve gift card data from a MongoDB database and includes a model schema for gift cards. The server listens on port 8900 and uses CORS and JSON middleware for handling requests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views1 page

Notes For React Js App

The document contains a server implementation using Express and Mongoose to manage gift cards. It defines an API endpoint to retrieve gift card data from a MongoDB database and includes a model schema for gift cards. The server listens on port 8900 and uses CORS and JSON middleware for handling requests.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// index.

js server file

const express = require('express')


const mongoose = require('mongoose')
const cors =require('cors')

const giftCardmodel = require('./models/GiftCards') //Database table model

const app=express()

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

mongoose.connect(URL)

app.get('/getCards',(req,res) => {
giftCardModel.find()
.then(cards => res.json(cards))
.catch(err => res.json(err))
})

app.listen(8900,() =>{
console.log("Server is started at 8900")
})

File 2

// server/models/GiftCards.js

const mongoose =require('mongoose')

const cardSchema =new mongoose.Schema({


imageUrl: String,
print: int,
description: String
})

const CardModel = mongoose.model("GiftCards",cardSchema)


Module.expor = CardModel

You might also like