On this page

Deno 1.x to 2.x Migration Guide

This document contains guidance for migrating from Deno version 1.x to the upcoming Deno 2.0.

Work in progress

Deno 2.0 is under active development - these API changes and recommendations will continue to be updated until the launch of 2.0.

API changes and deprecations Jump to heading

The following APIs have changed or deprecated between Deno 1.x and 2.x, and will be removed in 2.x - guidance for migrating to a newer set of APIs is provided for each impacted API below.

Deno.Buffer Jump to heading

Use Buffer from the Standard Library instead.

+ import { Buffer } from "jsr:@std/io/buffer";

- const buffer = new Deno.Buffer();
+ const buffer = new Buffer();

See deno#9795 for details.

Deno.Closer Jump to heading

Use Closer from the Standard Library instead.

+ import type { Closer } from "jsr:@std/io/types";

- function foo(closer: Deno.Closer) {
+ function foo(closer: Closer) {
  ...  
}

See deno#9795 for details.

Deno.close() Jump to heading

Use the .close() method on the resource instead.

- Deno.close(file.rid);
+ file.close();
- Deno.close(conn.rid);
+ conn.close();

See the Deno 1.40 blog post for details.

Deno.Conn.rid Jump to heading

Use Deno.Conn instance methods instead.

- await Deno.read(conn.rid, buffer);
+ await conn.read(buffer);
- await Deno.write(conn.rid, data);
+ await conn.write(data);
- Deno.close(conn.rid);
+ conn.close();
- await Deno.shutdown(conn.rid);
+ await conn.closeWrite();

See the Deno 1.40 blog post for details.

Deno.ListenTlsOptions.certChain Jump to heading

Use Deno.TlsCertifiedKeyPem.cert instead.

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
  hostname: "192.0.2.1",
  port: 80,
  caCerts: [caCert],
- certChain: Deno.readTextFileSync("./server.crt"),
+ cert: Deno.readTextFileSync("./server.crt"),
  key: Deno.readTextFileSync("./server.key"),
});

See deno#22274 for details.

Deno.ConnectTlsOptions.certFile Jump to heading

Use Deno.TlsCertifiedKeyPem.cert instead.

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
  hostname: "192.0.2.1",
  port: 80,
  caCerts: [caCert],
- certFile: "./server.crt",
+ cert: Deno.readTextFileSync("./server.crt"),
  key: Deno.readTextFileSync("./server.key"),
});

See deno#22274 for details.

Deno.ConnectTlsOptions.privateKey Jump to heading

Use Deno.TlsCertifiedKeyPem.cert instead.

const caCert = await Deno.readTextFile("./certs/my_custom_root_CA.pem");
using conn = await Deno.connectTls({
  hostname: "192.0.2.1",
  port: 80,
  caCerts: [caCert],
  cert: Deno.readTextFileSync("./server.crt"),
- keyFile: "./server.key",
+ key: Deno.readTextFileSync("./server.key"),
});

See deno#22274 for details.

Deno.copy() Jump to heading

Use copy() from the Standard Library instead.

+ import { copy } from "jsr:@std/io/copy";

...

- await Deno.copy(reader, writer);
+ await copy(reader, writer);

See deno#9795 for details.

Deno.customInspect Jump to heading

Use Symbol.for("Deno.customInspect") instead.

class Foo {
- [Deno.customInspect]() {
+ [Symbol.for("Deno.customInspect")] {
  }
}

See deno#9294 for details.

Deno.File Jump to heading

Use Deno.FsFile instead.

- function foo(file: Deno.File) {
+ function foo(file: Deno.FsFile) {
  ...
}

See deno#13661 for details.

Deno.flock() Jump to heading

Use Deno.FsFile.lock() instead.

- await Deno.flock(file.rid);
+ await file.lock();

See deno#22178 for details.

Deno.flockSync() Jump to heading

Use Deno.FsFile.lockSync() instead.

- Deno.flockSync(file.rid);
+ file.lockSync();

See deno#22178 for details.

Deno.fstatSync() Jump to heading

Use Deno.FsFile.statSync() instead.

- const fileInfo = Deno.fstatSync(file.rid);
+ const fileInfo = file.statSync();

See the Deno 1.40 blog post for details.

Deno.fstat() Jump to heading

Use Deno.FsFile.stat() instead.

- const fileInfo = await Deno.fstat(file.rid);
+ const fileInfo = await file.stat();

See the Deno 1.40 blog post for details.

Deno.FsWatcher.rid Jump to heading

Use Deno.FsWatcher instance methods instead.

- Deno.close(watcher.rid);
+ watcher.close();

See Deno 1.40 blog post for details.

Deno.ftruncateSync() Jump to heading

Use Deno.FsFile.truncateSync() instead.

- Deno.ftruncateSync(file.rid, 7);
+ file.truncateSync(7);

See the Deno 1.40 blog post for details.

Deno.ftruncate() Jump to heading

Use Deno.FsFile.truncate() instead.

- await Deno.ftruncate(file.rid, 7);
+ await file.truncate(7);

See the Deno 1.40 blog post for details.

Deno.funlock() Jump to heading

Use Deno.FsFile.unlock() instead.

- await Deno.funlock(file.rid);
+ await file.unlock();

See deno#22178 for details.

Deno.funlockSync() Jump to heading

Use Deno.FsFile.unlockSync() instead.

- Deno.funlockSync(file.rid);
+ file.unlockSync();

See deno#22178 for details.

Deno.futimeSync() Jump to heading

Use Deno.FsFile.utimeSync() instead.

- Deno.futimeSync(file.rid, 1556495550, new Date());
+ file.utimeSync(1556495550, new Date());

See the Deno 1.40 blog post for details.

Deno.futime() Jump to heading

Use Deno.FsFile.utime() instead.

- await Deno.futime(file.rid, 1556495550, new Date());
+ await file.utime(1556495550, new Date());

See the Deno 1.40 blog post for details.

Deno.isatty() Jump to heading

Use Deno.FsFile.isTerminal(), Deno.stdin.isTerminal(), Deno.stdout.isTerminal() or Deno.stderr.isTerminal() instead.

- Deno.isatty(file.rid);
+ file.isTerminal();
- Deno.isatty(Deno.stdin.rid);
+ Deno.stdin.isTerminal();
- Deno.isatty(Deno.stdout.rid);
+ Deno.stdout.isTerminal();
- Deno.isatty(Deno.stderr.rid);
+ Deno.stderr.isTerminal();

See the Deno 1.40 blog post for details.

Deno.iter() Jump to heading

Use iterateReader() from the Standard Library instead.

+ import { iterateReader } from "jsr:@std/io/iterate-reader";

- for await (const chunk of Deno.iter(reader)) {
+ for await (const chunk of iterateReader(reader)) {
  ...
}

See deno#9795 for details.

Deno.iterSync() Jump to heading

Use iterateReaderSync() from the Standard Library instead.

+ import { iterateReaderSync } from "jsr:@std/io/iterate-reader";

- for (const chunk of Deno.iterSync(reader)) {
+ for (const chunk of iterateReaderSync(reader)) {
  ...
}

See deno#9795 for details.

Deno.Listener.rid Jump to heading

Use Deno.Listener instance methods instead.

- Deno.close(listener.rid);
+ listener.close();

See the Deno 1.40 blog post for details.

Deno.ListenTlsOptions.certFile Jump to heading

Pass the certificate file contents to Deno.ListenTlsOptions.cert instead.

using listener = Deno.listenTls({
  port: 443,
- certFile: "./server.crt",
+ cert: Deno.readTextFile("./server.crt"),
  key: Deno.readTextFileSync("./server.key"),
});

See deno#12639 for details.

Deno.ListenTlsOptions.keyFile Jump to heading

Pass the key file contents to Deno.ListenTlsOptions.key instead.

using listener = Deno.listenTls({
  port: 443,
  cert: Deno.readTextFile("./server.crt"),
- keyFile: "./server.key",
+ key: Deno.readTextFileSync("./server.key"),
});

See deno#12639 for details.

Deno.readAllSync() Jump to heading

Use readAllSync() from the Standard Library instead.

+ import { readAllSync } from "jsr:@std/io/read-all";

...

- const data = Deno.readAllSync(reader);
+ const data = readAllSync(reader);

See deno#9795 for details.

Deno.readAll() Jump to heading

Use readAll() from the Standard Library instead.

+ import { readAll } from "jsr:@std/io/read-all";

...

- const data = await Deno.readAll(reader);
+ const data = await readAll(reader);

See deno#9795 for details.

Deno.Reader Jump to heading

Use Reader from the Standard Library instead.

+ import type { Reader } from "jsr:@std/io/types";

- function foo(closer: Deno.Reader) {
+ function foo(closer: Reader) {
  ...  
}

See deno#9795 for details.

Deno.ReaderSync Jump to heading

Use ReaderSync from the Standard Library instead.

+ import type { ReaderSync } from "jsr:@std/io/types";

- function foo(reader: Deno.ReaderSync) {
+ function foo(reader: ReaderSync) {
  ...  
}

See deno#9795 for details.

Deno.readSync() Jump to heading

Use the .readSync() method on the resource itself.

- Deno.readSync(conn.rid, buffer);
+ conn.readSync(buffer);
- Deno.readSync(file.rid, buffer);
+ file.readSync(buffer);

See deno#9795 for details.

Deno.read() Jump to heading

Use the .read() method on the resource itself.

- await Deno.read(conn.rid, buffer);
+ await conn.read(buffer);
- await Deno.read(file.rid, buffer);
+ await file.read(buffer);

See deno#9795 for details.

Deno.run() Jump to heading

Use new Deno.Command() instead.

- const process = Deno.run({ cmd: [ "echo", "hello world" ], stdout: "piped" });
- const [{ success }, stdout] = await Promise.all([
-   process.status(),
-   process.output(),
- ]);
- process.close();
+ const command = new Deno.Command("echo", {
+   args: ["hello world"]
+ });
+ const { success, stdout } = await command.output();
  console.log(success);
  console.log(new TextDecoder().decode(stdout));

See deno#16516 for details.

Deno.seekSync() Jump to heading

Use Deno.FsFile.seekSync() instead.

- Deno.seekSync(file.rid, 6, Deno.SeekMode.Start);
+ file.seekSync(6, Deno.SeekMode.Start);

See Deno 1.40 blog post for details.

Deno.seek() Jump to heading

Use Deno.FsFile.seek() instead.

- await Deno.seek(file.rid, 6, Deno.SeekMode.Start);
+ await file.seek(6, Deno.SeekMode.Start);

See Deno 1.40 blog post for details.

Deno.serveHttp() Jump to heading

Use Deno.serve() instead.

- const conn = Deno.listen({ port: 80 });
- const httpConn = Deno.serveHttp(await conn.accept());
- const e = await httpConn.nextRequest();
- if (e) {
-  e.respondWith(new Response("Hello World"));
- }
+ Deno.serve({ port: 80 }, () => new Response("Hello World"));

See the Deno 1.35 blog post for details.

Deno.Server Jump to heading

Use Deno.HttpServer instead.

- function foo(server: Deno.Server) {
+ function foo(server: Deno.HttpServer) {
  ...  
}

See deno#20840 for details.

Deno.shutdown Jump to heading

Use Deno.Conn.closeWrite() instead.

- await Deno.shutdown(conn.rid);
+ await conn.closeWrite();

See Deno 1.40 blog post for details.

Deno.stderr.rid Jump to heading

Use Deno.stderr instance methods instead.

- await Deno.write(Deno.stderr.rid, data);
+ await Deno.stderr.rid(data);
- Deno.close(Deno.stderr.rid);
+ Deno.stderr.close();
- Deno.isatty(Deno.stderr.rid);
+ Deno.stderr.isTerminal();

See Deno 1.40 blog post for details.

Deno.stdin.rid Jump to heading

Use Deno.stdin instance methods instead.

- await Deno.read(Deno.stdin.rid, buffer);
+ await Deno.stdin.read(buffer);
- Deno.close(Deno.stdin.rid);
+ Deno.stdin.close();
- Deno.isatty(Deno.stdin.rid);
+ Deno.stdin.isTerminal();

See Deno 1.40 blog post for details.

Deno.stdout.rid Jump to heading

Use Deno.stdout instance methods instead.

- await Deno.read(Deno.stdout.rid, buffer);
+ await Deno.stdout.read(buffer);
- Deno.close(Deno.stdout.rid);
+ Deno.stdout.close();
- Deno.isatty(Deno.stdout.rid);
+ Deno.stdout.isTerminal();

See Deno 1.40 blog post for details.

Deno.TcpConn.rid Jump to heading

Use Deno.TcpConn instance methods instead.

- await Deno.read(tcpConn.rid, buffer);
+ await tcpConn.read(buffer);
- await Deno.write(tcpConn.rid, data);
+ await tcpConn.write(data);
- Deno.close(tcpConn.rid);
+ tcpConn.close();
- await Deno.shutdown(tcpConn.rid);
+ await tcpConn.closeWrite();

See the Deno 1.40 blog post for details.

Deno.TlsConn.rid Jump to heading

Use Deno.TlsConn instance methods instead.

- await Deno.read(tlsConn.rid, buffer);
+ await tlsConn.read(buffer);
- await Deno.write(tlsConn.rid, data);
+ await tlsConn.write(data);
- Deno.close(tlsConn.rid);
+ tlsConn.close();
- await Deno.shutdown(tlsConn.rid);
+ await tlsConn.closeWrite();

See the Deno 1.40 blog post for details.

Deno.UnixConn.rid Jump to heading

Use Deno.UnixConn instance methods instead.

- await Deno.read(unixConn.rid, buffer);
+ await unixConn.read(buffer);
- await Deno.write(unixConn.rid, data);
+ await unixConn.write(data);
- Deno.close(unixConn.rid);
+ unixConn.close();
- await Deno.shutdown(unixConn.rid);
+ await unixConn.closeWrite();

See the Deno 1.40 blog post for details.

Deno.writeAllSync() Jump to heading

Use writeAllSync() from the Standard Library instead.

+ import { writeAllSync } from "jsr:@std/io/write-all";

...

- Deno.writeAllSync(writer, data);
+ writeAllSync(writer, data);

See deno#9795 for details.

Deno.writeAll() Jump to heading

Use writeAll() from the Standard Library instead.

+ import { writeAll } from "jsr:@std/io/write-all";

...

- await Deno.writeAll(writer, data);
+ await writeAll(writer, data);

See deno#9795 for details.

Deno.Writer Jump to heading

Use Writer from the Standard Library instead.

+ import type { Writer } from "jsr:@std/io/types";

- function foo(writer: Deno.Writer) {
+ function foo(writer: Writer) {
  ...  
}

See deno#9795 for details.

Deno.WriterSync Jump to heading

Use WriterSync from the Standard Library instead.

+ import type { WriterSync } from "jsr:@std/io/types";

- function foo(writer: Deno.WriterSync) {
+ function foo(writer: WriterSync) {
  ...  
}

See deno#9795 for details.

Deno.writeSync() Jump to heading

Use the .writeSync() method on the resource itself.

- Deno.writeSync(conn.rid, buffer);
+ conn.writeSync(buffer);
- Deno.writeSync(file.rid, buffer);
+ file.writeSync(buffer);

See deno#9795 for details.

Deno.write() Jump to heading

Use the .write() method on the resource itself.

- await Deno.write(conn.rid, buffer);
+ await conn.write(buffer);
- await Deno.write(file.rid, buffer);
+ await file.write(buffer);

See deno#9795 for details.

new Deno.FsFile() Jump to heading

Use Deno.openSync() or Deno.open() instead.

- const file = new Deno.FsFile(3);
+ const file = await Deno.open("/foo/bar.txt");