Skip to content

Instantly share code, notes, and snippets.

@azborgonovo
Last active October 26, 2016 19:47
Show Gist options
  • Save azborgonovo/083158d065ecedd509d7dcc31178f041 to your computer and use it in GitHub Desktop.
Save azborgonovo/083158d065ecedd509d7dcc31178f041 to your computer and use it in GitHub Desktop.
NodeJS commands and Javascript snippets
function isUserFromPortalFilter(portal) {
return function (user) {
return user.portal === portal;
};
}
// Usage
var portalXUsers = users.filter(isUserFromPortal('portalX'));
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;
});
}
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();
}
}
});
}
});
}
.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"}
}
// 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