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 from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import App from './App'; | |
| ReactDOM.render(<App />, document.getElementById('root')); |
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
| 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!')) |
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
| router.route('/:id').delete((req, res) => { | |
| Device.findByIdAndDelete(req.params.id) | |
| .then(() => res.json('Device deleted.')) | |
| .catch(err => res.status(400).json('Error: ' + err)); | |
| }); |
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
| 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)); | |
| }); |
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
| 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)); | |
| }); |
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
| const devicesRouter = require('./routes/devices'); | |
| const accountsRouter = require('./routes/accounts'); | |
| app.use('/devices', devicesRouter); | |
| app.use('/accounts', accountsRouter); |
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
| const deviceSchema = new Schema({ | |
| accountname: { | |
| type: String, | |
| required: true, | |
| }, | |
| description: { | |
| type: String, | |
| required: true, | |
| }, | |
| duration: { |
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
| const accountSchema = new Schema({ | |
| accountname: { | |
| type: String, | |
| required: true, | |
| unique: true, | |
| trim: true, | |
| minlength: 3 | |
| } | |
| },{ | |
| timestamps: true |
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
| 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!") | |
| }) |
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
| # 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: |