Node.js Compatibility

Deno Deploy natively supports importing built-in Node.js modules like fs, path, and http through node: specifiers. This allows running code originally written for Node.js without changes in Deno Deploy.

Here is an example of a Node.js HTTP server running on Deno Deploy:

import { createServer } from "node:http";
import process from "node:process";

const server = createServer((req, res) => {
  const message = `Hello from <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mrow><mi>p</mi><mi>r</mi><mi>o</mi><mi>c</mi><mi>e</mi><mi>s</mi><mi>s</mi><mi mathvariant="normal">.</mi><mi>e</mi><mi>n</mi><mi>v</mi><mi mathvariant="normal">.</mi><mi>D</mi><mi>E</mi><mi>N</mi><msub><mi>O</mi><mi>R</mi></msub><mi>E</mi><mi>G</mi><mi>I</mi><mi>O</mi><mi>N</mi></mrow><mi>a</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">{process.env.DENO_REGION} at </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.8778em;vertical-align:-0.1944em;"></span><span class="mord"><span class="mord mathnormal">p</span><span class="mord mathnormal">rocess</span><span class="mord">.</span><span class="mord mathnormal">e</span><span class="mord mathnormal">n</span><span class="mord mathnormal" style="margin-right:0.03588em;">v</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.02778em;">D</span><span class="mord mathnormal" style="margin-right:0.10903em;">EN</span><span class="mord"><span class="mord mathnormal" style="margin-right:0.02778em;">O</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.3283em;"><span style="top:-2.55em;margin-left:-0.0278em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.00773em;">R</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.15em;"><span></span></span></span></span></span></span><span class="mord mathnormal">EG</span><span class="mord mathnormal" style="margin-right:0.07847em;">I</span><span class="mord mathnormal" style="margin-right:0.10903em;">ON</span></span><span class="mord mathnormal">a</span><span class="mord mathnormal">t</span></span></span></span>{new Date()}`;
  res.end(message);
});

server.listen(8080);

You can see this example live here: https://dash.deno.com/playground/node-specifiers

When using node: specifiers, all other features of Deno Deploy are still available. For example, you can use Deno.env to access environment variables even when using Node.js modules. You can also import other ESM modules from external URLs as usual.

The following Node.js modules are available:

  • assert
  • assert/strict
  • async_hooks
  • buffer
  • child_process
  • cluster
  • console
  • constants
  • crypto
  • dgram
  • diagnostics_channel
  • dns
  • dns/promises
  • domain
  • events
  • fs
  • fs/promises
  • http
  • http2
  • https
  • module
  • net
  • os
  • path
  • path/posix
  • path/win32
  • perf_hooks
  • process
  • punycode
  • querystring
  • readline
  • stream
  • stream/consumers
  • stream/promises
  • stream/web
  • string_decoder
  • sys
  • timers
  • timers/promises
  • tls
  • tty
  • url
  • util
  • util/types
  • v8
  • vm
  • worker_threads
  • zlib

The behavior of these modules should be identical to Node.js in most cases. Due to the sandboxing behaviour of Deno Deploy, some features are not available:

  • Executing binaries with child_process
  • Spawning workers using worker_threads
  • Creating contexts and evaluating code with vm

Note: the emulation of Node.js modules is sufficient for most use cases, but it is not yet perfect. If you encounter any issues, please open an issue.