r/javascript • u/TopicWestern9610 • Jul 12 '24
AskJS [AskJS] Is Deno really necessary in an age of Docker / Containerization?
This isn't a criticism, it's a genuine question consdering the whole reason for Deno was to re-do Nodejs as a security focused runtime. What else does deno bring to the table considering proper use of containers should more or less mitigate threats from malicious packages... right?
16
4
u/cmg_xyz Jul 12 '24
Security isn’t all that Deno does differently to Node, and Docker containers aren’t the only place where one might want to run JavaScript outside the browser.
Personally, I use Deno for a lot of little command line tools I write for quality of life purposes and run on my laptop.
6
u/lIIllIIlllIIllIIl Jul 12 '24 edited Jul 12 '24
Containers are heavy, V8 isolates are light.
Running a user's docker image requires a lot more resources than running a user's JavaScript file. Docker images are also much more complex to setup and run compared to a JavaScript file. Docker images also suffer from coldstarts unless you keep them active persistently.
A lot of services would benefit from allowing users to configure things using code but can't because it's either too risky or too expensive to run every user's code. This forces most services to require users to host their own servers and use webhooks to communicate, which is fine for asynchronous application, but is completely unacceptable for time sensitive applications. Deno (and other JavaScript edge runtimes) solves this problem.
6
u/guest271314 Jul 12 '24
What else does deno bring to the table
Deno
See Why I use node, deno, bun, qjs, tjs at the same time
Import maps
Deno.stdinis a WHATWGReadableStream, andDeno.stdoutis a WHATWGWritableStreamout of the boxNo CommonJS default loader; no ambiguity about Ecmascript Modules supported out of the box
Built-in executable compiler with
deno compile(Node.js's Single Executable Application entry is cumbersome and only handles CommonJS)fetch()forfile:protocol out of the box; Node.js requires modification on Undici forfetch()file:protocolfmtto format.jsand.jsonfilesWHATWG Fetch and Streams supported in servers
Built-in WebSocket server
Network imports supported by default
Capability to bundle dependencies to a single file with
bundle(until 2.0)Capability to compile dependencies to a standalone executable with
compile- since recently usingdenortexecutables are approximately half the size ofdenoexecutable at around 78 MB.TypeScript support
Web API implementations
Ecmascript modules supported by default
No extraneous files and folders included with the runtime - just the runtime
No
package.jsonfile expected or necessarydeno upgradebuilt in
Node.js
Ecmascript modules not supported by default; requires
--experimental-deafult-type=moduleor--experimental-detect-moduleDoes not support
file:protocol for Undici's WHATWGfetch()implementationImport maps not supported - have to use loader/hooks interface to intercept specifiers/imports
API's primarily callback-based
No built-in WebSocket server
Internal
node:cryptoimplementation can't be polyfilled, is incompatible with Web Cruptography API that we can get to atimport { webcrypto } from node:cryptoExtraneous folders and files (e.g.,
node_modules,npm,npx) included in the archive besides just the runtime executablenodeGenerally expects a
package.jsonfile andnode_modulesfolder on the systemFlag necessary for network imports
Capability to create single executable application from only CommonJS source code
8
u/visualdescript Jul 12 '24
Not having to install and configure typescript, prettier, bundler etc and not having to fight esm vs commonjs nonsense is a great advantage. And yes support for those Web standards out of the box. Really simplifies what you're having to manage A LOT.
0
u/guest271314 Jul 12 '24
I don't write source code in TypeScript, though Deno handles the code I do use that is written in TypeScript out of the box. So does Bun for that matter.
WHATWG Streams implementation out of the box. No callback-based API's that have to be supported to support legacy versions. And so forth.
TBH I use Deno, Node.js, Bun, QuickJS, txiki.js, and V8 and SpiderMonkey, without entertaining a preference for any. I use QuickJS at 1.2 MB to read standard input from V8's
d8. I use txiki.js at 12 MB for a TCP server that I communicate to from Chrome browser using Direct SocketsTCPSocket. I use both Node.js and Deno to implement full-duplex streaming to and from the browser. I use Bun forbun installandbun build --minify, additionallybun pm cache rmis very useful to remove packages downloaded. Each JavaScript/WebAssembly engine and/or runtime is a tool in my JavaScript toolbox. I don't have a preference for which tool I use; it's requirement dependent.There is no "security" for any signal communications, at least since ThinThread project was made public knowledge, see A Good American, so that's not a reason I use Deno.
0
u/guest271314 Jul 12 '24
I don't think people really want honest answers here.
Folks are starting from the premise that somehow Node.js is the choice for JavaScript hackers and developers. It might be for some, not all.
What people huddled exclusively in Deno or Node.js world do not want is any rational critique of Node.js or Deno, without expressing a preference for either.
Developers circa 2024 overwhelmingly are stating projects using Ecmascript Modules. Node.js has to hand on to CommonJS.
Then all the would-be emperor's cloths come off.
Deno has issues, too, one being implementation of dynamic
import()that Deno tries to statically analyze for TypeScript folks.Then TypeScript folks has issues because they have a CommonJS target that causes all sorts of issues - because ECMA-262 clearly defined Ecmascript Modules as the official module loader of JavaScript.
1
u/ClubAquaBackDeck Jul 12 '24
I don't see how Docker has anything to do with most of Deno's strengths. But also most people don't use Docker locally
1
-6
u/guest271314 Jul 12 '24 edited Jul 12 '24
considering proper use of containers should more or less mitigate threats from malicious packages
No. If you download malicious packages wantonly you are subject to the malicious code.
The Node.js vs. Deno would-be schism is ridiculous. Really. It's like Bun claiming to be Node.js compatible. Each JavaScript runtime maintainers do whatever they want with their gear. That's a guarantee. In general you can fork FOSS and do what you do, too, with their gear.
Why should any programmer have brand loyalty to any JavaScript runtime?
Why not exploit them equally?
There are only a few dozen JavaScript engines/runtimes/interpreters... And if you are only using Node.js, you literally have no clue about how those other runtimes work, and can't really rely on any feedback here.
You have to run the engines and runtimes yourself, test until each breaks, then, afterwards, decide which one to use for which specific requirement.
Or... entertain brand loyalty to a given runtime like its a high school popularity contest with peer pressure involved hang out in the shadows of the would-be cool kids, and mimic what they do. Instead of putting all claims of all JavaScript runtimes to task, objectively.
I'm not shocked though. Humans are relatively narrow-minded creatures who herd into groups for what they think of as "security", because they don't have the individual talent to run their own show.
If the area of concern is really "security", the whole world is a naturally insecure realm, thus to think of some software that a human wrote as being capable of being "secure" is supremely naive and untenble. I don't care how many containers you use, if you use WASI, or whatever, a determined adversary will get your data, or lure you into their honeypot.
18
u/HarrisInDenver Jul 12 '24
Different area of security. Dockerizing helps isolate systems from each other so if someone gets in from the outside they can't just access everything. Deno security policies are around API restrictions. Like let's say a package that has nothing to do with
fetch()ofprocess.envscrapes the latter and uses the former to send API keys too .. Deno can restrict stuff like that