Skip to content

Instantly share code, notes, and snippets.

@sespinosa
sespinosa / let.js
Created July 24, 2018 01:45
Let example (scope)
let x = 1
var y = 1
console.log("\nInitial Values")
console.log("x: ", x)
console.log("y: ", y)
/* OUTPUT:
* x: 2
* y: 2
*/
App.findById(id, (err, app) => {
Object.assign(app.config, req.body) // Aca mutamos el objeto app original.
app.save(err => {
if(err) return res.status(500)
if(!app) => return res.status(404)
res.status(200).send(app)
})
})
@sespinosa
sespinosa / addWhiteSpaceAtTheEnd.js
Created September 9, 2017 18:36
addWhiteSpace at the end function
function addWhiteSpaceAtTheEnd(str, len) {
if(str.length >= len) return str;
var delta = len - str.length;
var res = str;
for(var i = 0 ; i < delta ; i++) {
res = res + " ";
}
return res;
}
var request = require('request');
var URL = 'https://jsonplaceholder.typicode.com/posts/';
var requestHandler = function(err, res, body) {
if(err) {
// aca controlas el error.
console.log('ERROR:' + err);
return;
var myController = {
root: function(req, res) {
if(req.session().algo) {
res.view('index', {
foo: 'bar'
});
}
else {
res.view('login')
}