Skip to content

Instantly share code, notes, and snippets.

@rkmax
Created February 24, 2017 00:28
Show Gist options
  • Save rkmax/d1eaf863abff5b633ead1fa63f042521 to your computer and use it in GitHub Desktop.
Save rkmax/d1eaf863abff5b633ead1fa63f042521 to your computer and use it in GitHub Desktop.
fs.writeFile('/tmp/a.txt', 'data', function(err, result) => {
fs.writeFile('/tmp/b.txt', 'data', function(err, result) => {
fs.writeFile('/tmp/c.txt', 'data', function(err, result) => {
fs.writeFile('/tmp/d.txt', 'data', function(err, result) => {
console.log('exito!');
});
});
});
});
// 1.js
async.map([
{path: 'tmp/a.txt', data: data}
], (info, cb) => fs.writeFile(info.path, info.data, cb), () => {
console.log('exito!');
});
function listar() {
return Promise.resolve(true);
}
function preController(req, res, next) {
if (req.body.hello) {
req.hello = true;
next();
} else {
next(new Error('Hello is missing'));
}
}
function controller(req, res, next) {
listar()
.then((result) => res.json(result))
.catch((err) => next(err));
}
function controller(req, res, next) {
listar((err, result) => {
if (err) {
next(err);
} else {
res.json(result);
}
});
}
function errorHandler1(err, req, res, next) {
if (err.isMongoose) {
//
} else {
next(err);
}
}
function errorHandler2(err, req, res, next) {
res.status(500).send(err);
}
app.use(errorHandler1);
app.use(errorHandler2);
listar()
.then((result) => console.log('result', result))
.catch((err) => console.error('result', err));
listar((err, result) => {
if (err) {
console.error(err);
} else {
console.log('result', result)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment