This file contains 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 getData(){ | |
const a = await someFunction().catch((error)=>console.log(error)); | |
const b = await someOtherFunction().catch((error)=>console.log(error)); | |
if(a && b ) console.log("some result") | |
} |
This file contains 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
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works | |
const axios = require('axios'); // promised based requests - like fetch() | |
function getCoffee() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee | |
}); | |
} |
This file contains 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
// Add a 401 response interceptor | |
window.axios.interceptors.response.use(function (response) { | |
return response; | |
}, function (error) { | |
if (401 === error.response.status) { | |
swal({ | |
title: "Session Expired", | |
text: "Your session has expired. Would you like to be redirected to the login page?", | |
type: "warning", | |
showCancelButton: true, |
Collection of projects I'm doing while working through the Free Code Camp full stack web developer certifications.
- Build a Tribute Page | Requirements | Demo | Source Code
- Build a Personal Portfolio Page | Requirements | Demo | Source Code
Visit the new improved script here! Smooth scroll to top of page (Improved!)
If you need a plain JavaScript function to add a smooth scrolling back to the top of the page, you can use this script.
- Add an id of "top" to the
<body>
tag. Like this:<body id="top">
- Add the
onclick
function to the link. Like this:<a href="#top" onclick="scrollToTop(); return false">Back to Top ↑</a>
This file contains 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
var mongoose = require('mongoose'); | |
mongoose.connect('mongodb://localhost/test'); | |
var db = mongoose.connection; | |
db.on('error', function() { | |
return console.error.bind(console, 'connection error: '); | |
}); | |
NewerOlder