2 ms·
After my 3 years coding CoffeeScript, I cannot live without 'errTo', similar helper I wrote a while ago: errTo = require 'errto' readDirectoryAsync =
by ashtuchkin 12y ago
After my 3 years coding CoffeeScript, I cannot live without 'errTo', similar helper I wrote a while ago:
errTo = require 'errto'
readDirectoryAsync = (catalog, cb) ->
fs.readdir catalog, errTo cb, (filenames) -> # Notice no 'err' argument.
# Error check is done automatically in errTo and cb(err) is called on error.
# Subsequent code is called ONLY when no error given.
callback null, filenames
# Express sample.
app.get '/', (req, res, next) ->
readDirectoryAsync __dirname, errTo next, (filenames) -> # Use Express error handling by calling next(err)
res.send filenames
https://github.com/ashtuchkin/errto https://github.com/ashtuchkin/errto