Node.js
It's important to understand that node isn't about functions being asynchronous all the time. It's about i/o being asynchronous and non-blocking. If your function doesn't do any i/o, node isn't going to help you make it asynchronous. It provides tools that will allow you to do that though. Like child processes. That's what felix's answer is getting at. Your function can spawn a child process to do your work and it will execute off of the main event loop.
How to catch all?
process.on('uncaughtException', (err) => {
fs.writeSync(1, `Caught exception: ${err}\n`);
});
How to use local (private) package?
Use git submodule
# when clone, remember to clone with submodules
git clone --recursive git@REPO-URL
# to update
git submodule update --remote
npm install
NOTE there is a bug for npm update
: it doesn't work with local package now, see NPM #7426
"my-package": "file:./my-package",
So my workaroud for now is, go to node_moduels folder and delete the package folder, then npm install again.
Reference:
FS
How to get the base file name: 'a.ext' -> 'a'?
# If you know the ext name in advance:
name = path.basename filename, '.ext'
# otherwise
name = path.basename(filename).slice 0, -path.extname(filename).length
How to glob in node?
glob = require 'glob'
dir = "d:\\Test"
glob '**/*.ext', {cwd: dir}, (error, files)->
if error
console.log error
return
_.each files, (file)->
# file: "\\sub folder\\1.ext"
filePath = Path.join dir, file # -> "d:\\Test\\sub folder\\1.ext"
filename = Path.basename file # -> "1.ext"
fileBasename = Path.basename file, '.ext' # => "1"
Frontend
How to get url of root with domain?
var root = location.protocol + '//' + location.host;
http://bl.ocks.org/abernier/3070589 and http://stackoverflow.com/a/1368295/166286
A way to generate and download CSV files client-side
Last updated