Skip to content

Instantly share code, notes, and snippets.

View welll's full-sized avatar
🏠
Working from home

Wellington Soares welll

🏠
Working from home
View GitHub Profile
@welll
welll / aggregate.js
Created November 1, 2016 04:05
Aggregate data from MongoDB with Node.js and mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Database connection
var uristring = 'mongodb://localhost/test';
var mongoOptions = { };
mongoose.connect(uristring, mongoOptions, function (err, res) {
if (err) {
console.log('Error when connecting to: ' + uristring + '. ' + err);
@welll
welll / episode.js
Created January 16, 2017 14:35 — forked from mpj/episode.js
Code from the "Dependency Injection Basics" episode of Fun Fun Function
const assert = require('assert')
function getAnimals(fetch, id) {
return fetch('http://api.animalfarmgame.com/animals/' + id)
.then(response => response.json())
.then(data => data.results[0])
}
describe('getAnimals', () => {
it('calls fetch with the correct url', () => {
var dependency1 = require('./dep1');
export.fooBar = dep
@welll
welll / callback-hell.js
Last active March 14, 2017 07:13
AvenueCode - Blog Post
const AWS = require(`aws-sdk`)
const fs = require(`fs`)
const path = require(`path`)
const dir = `./sample-dir`
const bucket = `bucket-name`
const s3bucket = new AWS.S3({params: {Bucket: bucket}})
fs.readdir(dir, (err, files) => {
@welll
welll / callback-hell-async.js
Created March 14, 2017 08:23
Callback Hell Async/Await
const AWS = require(`aws-sdk`)
const fs = require(`fs`)
const path = require(`path`)
const dir = `./sample-dir`
const bucket = `bucket-name`
const s3bucket = new AWS.S3({params: {Bucket: bucket}})
async function readDirAsync(path) {
@welll
welll / long-list-argument.js
Created March 14, 2017 09:10
AvenueCode - Blog Post
function createProduct(id, name, description, sku, colors, sizes, price, imageURL, thumbnailURL){
//
//
}
@welll
welll / missing-return.js
Created March 14, 2017 09:22
AvenueCode - Blog Post
/* missing a RETURN statement */
fs.readFile(`${filePath}`, (err, data) => {
if (err) {
console.log(`Error reading file: ${filePath}`)
}
//...
//code
//...
@welll
welll / checking-image.js
Created March 14, 2017 16:12
Checking if the image was loaded
function checkIfImageExist(src, cb) {
var img = new Image();
img.onload = function() {
cb(null)
}
img.onerror = function(e) {
@welll
welll / global-value.js
Created March 15, 2017 15:40
AvenueCode - Blog Post
global.myNumber = 5; //Global variable initialized to value 5.
node debug $(which gulp) taskName