Last active
October 26, 2016 19:47
-
-
Save azborgonovo/083158d065ecedd509d7dcc31178f041 to your computer and use it in GitHub Desktop.
NodeJS commands and Javascript snippets
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 isUserFromPortalFilter(portal) { | |
return function (user) { | |
return user.portal === portal; | |
}; | |
} | |
// Usage | |
var portalXUsers = users.filter(isUserFromPortal('portalX')); |
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 forEach(array, asyncAction, callback) { | |
var promises = []; | |
array.forEach(function (item) { | |
promises.push(new Promise(function (resolve, reject) { | |
asyncAction(item, resolve); | |
})); | |
}); | |
Promise.all(promises) | |
.then(function () { | |
return callback(); | |
}).catch(function (err) { | |
throw 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
function forEach(array, asyncAction, callback) { | |
var size = array.length; | |
var count = 0; | |
var nextLoop = true; | |
array.forEach(function (item) { | |
if (nextLoop == true) { | |
asyncAction(item, function (err) { | |
if (err) { | |
nextLoop = false; | |
return callback(err); | |
} else { | |
if (++count === size) { | |
return callback(); | |
} | |
} | |
}); | |
} | |
}); | |
} |
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
.vscode > launch.js | |
{ | |
"name": "Run mocha tests", | |
"type": "node", | |
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", | |
"stopOnEntry": false, | |
"args": [], | |
"cwd": "${workspaceRoot}", | |
"runtimeExecutable": null, | |
"env": { "NODE_ENV": "development"} | |
} |
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
// Starts a NodeJS application | |
node app.js | |
// Init the package.json file | |
npm init | |
// Install a node package in global mode | |
npm install <module_name> [-g|--global] | |
// Install a node package and save | |
npm i <module_name> [-S|--save] | |
// Install a node package and save as a dev dependency | |
npm i <module_name> [-D|--save-dev] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment