Skip to content

Instantly share code, notes, and snippets.

View TheArhaam's full-sized avatar
🥼
EL. PSY. KONGROO.

Arhaam Patvi TheArhaam

🥼
EL. PSY. KONGROO.
View GitHub Profile
@TheArhaam
TheArhaam / App.js
Last active November 19, 2020 19:02
randomlist App.js
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')
@TheArhaam
TheArhaam / list.js
Last active November 19, 2020 18:25
randomlist list.js
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); })
})
@TheArhaam
TheArhaam / item.model.js
Created November 19, 2020 17:47
randomlist item.model.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
const itemSchema = new Schema(
{
name: {
type: String,
required: true,
},
}
@TheArhaam
TheArhaam / server.js
Last active November 19, 2020 17:34
randomlist server.js
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
@TheArhaam
TheArhaam / .env
Created November 19, 2020 17:16
randomlist .env
PORT=5000
MONGODB_URI=mongodb://localhost:27017/randomListDB