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 express = require('express') | |
| const app = express() | |
| const port = 3000 | |
| app.get('/', (req, res) => res.send('Hello World!')) | |
| app.listen(port, () => console.log(`Example app listening on port ${port}!`)) |
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 express = require('express'); | |
| const app = express(); | |
| const port = 3000; | |
| app.get('/', (req, res) => res.send('Hello World!')); | |
| app.listen(port, () => console.log(`Example app listening on port ${port}!`)); |
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
| require('dotenv').config(); | |
| const express = require('express'); | |
| const mongoose = require('mongoose'); | |
| const Posts = require('./models/posts'); | |
| const app = express(); | |
| const port = 3000; | |
| mongoose.connect(process.env.MONGO_URI, { | |
| useNewUrlParser: 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
| app.get('/posts', async (req, res) => { | |
| // destructure page and limit and set default values | |
| const { page = 1, limit = 10 } = req.query; | |
| try { | |
| // execute query with page and limit values | |
| const posts = await Posts.find() | |
| .limit(limit * 1) | |
| .skip((page - 1) * limit) | |
| .exec(); |
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
| function getToDo() { | |
| axios.get('https://jsonplaceholder.typicode.com/todos/1') | |
| .then(response => console.log(response.data)) | |
| .catch(error => console.error(error)) | |
| } |
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
| async function getToDo() { | |
| try { | |
| const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1'); | |
| console.log(response); | |
| } catch (error) { | |
| console.log(error); | |
| } | |
| } |
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 db = require('../models'); | |
| module.exports = { | |
| findById: function(req, res) { | |
| const { id } = req.query; | |
| db.Book.find(id) | |
| .sort({ date: -1 }) | |
| .then(data => res.json(data)) | |
| .catch(err => res.json(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 db = require("../models"); | |
| module.exports = { | |
| findAll: async function(req, res) { | |
| const { id } = req.query; | |
| try { | |
| const books = await db.Book.find(id).sort({ date: -1 }); | |
| res.json(books); | |
| } catch (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
| import request from 'superagent'; | |
| ... | |
| const getCustomer = (id) => { | |
| request | |
| .get(`${process.env.CUSTOMERS_ENDPOINT}/customer/${id}`) | |
| .set('Authorization', this.$store.state.idToken) | |
| .then(response => { | |
| this.customers = response.body.userProfiles; |
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 request from 'superagent'; | |
| ... | |
| const getCustomer = async (id) => { | |
| try { | |
| const response = await request | |
| .get(`${process.env.CUSTOMERS_ENDPOINT}/customer/${id}`) | |
| .set('Authorization', this.$store.state.idToken) |
OlderNewer