This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect } from 'react'; | |
import axios from 'axios' | |
function Main() { | |
const [data,setdata] = useState([]) | |
useEffect(() => { | |
async function fetchData() { | |
const res = await axios.get("https://user-details-mern.herokuapp.com/details") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Navbar from './Navbar' | |
import Main from './Main' | |
import { Link, browserHistory, IndexRoute, BrowserRouter as Router, Route, Switch } from 'react-router-dom'; | |
function Home() { | |
return ( | |
<div className="App"> | |
<Router browserHistory> | |
<Navbar /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './App.css'; | |
import { Link, browserHistory, IndexRoute, BrowserRouter as Router, Route, Switch } from 'react-router-dom'; | |
import Home from './Home' | |
import AddDetails from './AddDetails' | |
function App() { | |
return ( | |
<div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get("/details", function (req, res) { | |
UserDetails.find((err, data) => { | |
if (err) { | |
res.status(501).send(err) | |
} | |
else { | |
res.status(200).send(data) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import mongoose from 'mongoose'; | |
const UserDataSchema = mongoose.Schema({ | |
Name: String, | |
FName: String, | |
Address: String, | |
PhonNo: String, | |
Email: String | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "Kia Sonet", | |
"Model": "Sonet", | |
"Price": "Rs. 6.79 - 13.19 Lakh", | |
"meta":{ | |
"Fuel_Type": "Petrol / diesel", | |
"Mileage":"18.4 - 24.1 Kmpl", | |
"Seating_Capacity": 5 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "rest_api", | |
"version": "1.0.0", | |
"description": "Rest API using MEN (MongoDB,ExpressJs and NodeJs)", | |
"main": "server.js", | |
"type": "module", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"start": "nodemon server.js" | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import express from 'express' | |
import mongoose from "mongoose" | |
import Cors from 'cors' | |
import Cars from './Cars' | |
var app = express() | |
var port = process.env.PORT || 8080 | |
app.use(express.json()) | |
app.use(Cors()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get("/Cars", function (req, res) { | |
try { | |
Cars.find((err, data) => { | |
if (err) { | |
res.status(500).send(err) | |
} | |
else { | |
res.status(200).send(data) | |
} |