4 ms·
> Can compile Javascript sources to executables with no external dependency. Is QuickJS a viable way to write command-line apps in JavaScript? In particular, d
by pansa2 6y ago
> Can compile Javascript sources to executables with no external dependency.
Is QuickJS a viable way to write command-line apps in JavaScript? In particular, does it have enough of a standard library to work with, or would it be a struggle because (I assume) it can’t use packages from NPM?
I know there’s the alternative of bundling Node.js and V8 into an executable, but the resulting binaries are large - it feels like the command-line equivalent of using Electron.
- MobiusHorizons 6y agoIt's quite possible, especially for simple cli apps. The io is different from node though, so takes a little getting used to.
- untog 6y agoIt has a very small standard library: https://bellard.org/quickjs/quickjs.html#std-module https://bellard.org/quickjs/quickjs.html#std-module It would be enough for a good number of CLI tools, I'd think. But one big issue is going to be that every library on NPM is hardcoded to use Node's modules (e.g. fs) so you're not going to be able to use any external modules at all.
- tomjakubowski 6y agoThis is untrue. There are plenty of modules published to npm which don't use node APIs, often specifically so they can be used in many runtimes. Here's one example: https://www.npmjs.com/package/squat https://www.npmjs.com/package/squat
- untog 6y agoOK, to be clearer: almost all the libraries published to NPM that would use the functions in QuickJS’s std module instead use Node modules and there is no compatibility layer. So yes, there are plenty of pure JS modules. But if you want to read a file from a disk you’re going to end up with a library that assumes you’re using Node.
- megous 6y agoI take the bindings provided with quickjs more as an example on how to write them.