Skip to content

Instantly share code, notes, and snippets.

View ting11222001's full-sized avatar
🎯
Focusing

Li-Ting Liao ting11222001

🎯
Focusing
View GitHub Profile
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
ReactDOM.render(<App />, document.getElementById('root'));
router.route('/update/:id').post((req, res) => {
Device.findById(req.params.id)
.then(device => {
device.username = req.body.accountname;
device.description = req.body.description;
device.duration = Number(req.body.duration);
device.date = Date.parse(req.body.date);
device.save()
.then(() => res.json('Device updated!'))
router.route('/:id').delete((req, res) => {
Device.findByIdAndDelete(req.params.id)
.then(() => res.json('Device deleted.'))
.catch(err => res.status(400).json('Error: ' + err));
});
router.route('/add').post((req, res) => {
const accountname = req.body.accountname;
const newAccount = new Account({accountname});
newAccount.save()
.then(() => res.json('Account added!'))
.catch(err => res.status(400).json('Error: ' + err));
});
const router = require('express').Router();
let Account = require('../model/account.model');
router.route('/').get((req, res) => {
Account.find()
.then(accounts => res.json(accounts))
.catch(err => res.status(400).json('Error: ' + err));
});
const devicesRouter = require('./routes/devices');
const accountsRouter = require('./routes/accounts');
app.use('/devices', devicesRouter);
app.use('/accounts', accountsRouter);
const deviceSchema = new Schema({
accountname: {
type: String,
required: true,
},
description: {
type: String,
required: true,
},
duration: {
const accountSchema = new Schema({
accountname: {
type: String,
required: true,
unique: true,
trim: true,
minlength: 3
}
},{
timestamps: true
const uri = process.env.ATLAS_URI;
mongoose.connect(uri, {useNewUrlParser: true, useCreateIndex: true, useUnifiedTopology: true});
const connection = mongoose.connection;
connection.once('open', () => {
console.log("MongoDB connection established successfully!")
})
# Setup project:
$ mkdir DEVICE_LOG_MERN_DEPLOY
$ cd DEVICE_LOG_MERN_DEPLOY
$ npx create-react-app tracker-app
$ cd tracker-app
# Start react:
$ npm start
# Initiate node: