Skip to content

Instantly share code, notes, and snippets.

View kluu1's full-sized avatar

Kevin Luu kluu1

  • Atlanta, GA
View GitHub Profile
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}!`))
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}!`));
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,
@kluu1
kluu1 / app.js
Last active April 16, 2020 15:41
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();
@kluu1
kluu1 / todo.js
Last active March 16, 2020 12:44
function getToDo() {
axios.get('https://jsonplaceholder.typicode.com/todos/1')
.then(response => console.log(response.data))
.catch(error => console.error(error))
}
async function getToDo() {
try {
const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1');
console.log(response);
} catch (error) {
console.log(error);
}
}
@kluu1
kluu1 / books.js
Last active March 16, 2020 13:07
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));
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) {
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;
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)