This file contains 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 { useState, useEffect } from 'react' | |
import './App.css'; | |
import axios from 'axios'; | |
axios.defaults.baseURL = "http://localhost:5000/" | |
const App = () => { | |
const [list, setList] = useState([]); | |
useEffect(() => { | |
axios.get('/list') |
This file contains 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
const router = require("express").Router(); | |
let Item = require("../../models/item.model"); | |
// POST - Add new item to list | |
router.post("/item", (request, response) => { | |
Item({ name: request.body.item }).save() | |
.then((item) => { response.status(200).json("Item Added Successfully!"); }) | |
.catch((err) => { response.status(400).json("Unable to add item: " + err); }) | |
}) |
This file contains 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
const mongoose = require("mongoose"); | |
const Schema = mongoose.Schema; | |
const itemSchema = new Schema( | |
{ | |
name: { | |
type: String, | |
required: true, | |
}, | |
} |
This file contains 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
const express = require("express"); | |
const mongoose = require("mongoose"); | |
const cors = require("cors"); | |
const app = express(); | |
require("dotenv").config(); | |
app.use(cors()); | |
app.use(express.json()); | |
// MONGODB CONNECTION |
This file contains 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
PORT=5000 | |
MONGODB_URI=mongodb://localhost:27017/randomListDB |