Skip to main content

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

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

Use Buffer from the Standard Library instead.

+ import { Buffer } from "https://deno.land/std/io/buffer.ts";

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

See deno#9795 for details.

Deno.Closer

Use Closer from the Standard Library instead.

+ import type { Closer } from "https://deno.land/std/io/types.ts";

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

See deno#9795 for details.

Deno.close()

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

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

Use Deno.ConnectTlsOptions.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

Use Deno.ConnectTlsOptions.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

Use Deno.ConnectTlsOptions.key 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()

Use copy() from the Standard Library instead.

+ import { copy } from "https://deno.land/std/io/copy.ts";

...

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

See deno#9795 for details.

Deno.customInspect

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

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

See deno#9294 for details.

Deno.File

Use Deno.FsFile instead.

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

See deno#13661 for details.

Deno.flock()

Use Deno.FsFile.lock() instead.

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

See deno#22178 for details.

Deno.flockSync()

Use Deno.FsFile.lockSync() instead.

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

See deno#22178 for details.

Deno.fstatSync()

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()

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

Use Deno.FsWatcher instance methods instead.

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

See Deno 1.40 blog post for details.

Deno.ftruncateSync()

Use Deno.FsFile.truncateSync() instead.

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

See the Deno 1.40 blog post for details.

Deno.ftruncate()

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()

Use Deno.FsFile.unlock() instead.

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

See deno#22178 for details.

Deno.funlockSync()

Use Deno.FsFile.unlockSync() instead.

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

See deno#22178 for details.

Deno.futimeSync()

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()

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()

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()

Use iterateReader() from the Standard Library instead.

+ import { iterateReader } from "https://deno.land/std/io/iterate_reader.ts";

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

See deno#9795 for details.

Deno.iterSync()

Use iterateReaderSync() from the Standard Library instead.

+ import { iterateReaderSync } from "https://deno.land/std/io/iterate_reader.ts";

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

See deno#9795 for details.

Deno.Listener.rid

Use Deno.Listener instance methods instead.

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

See the Deno 1.40 blog post for details.

Deno.ListenTlsOptions.certFile

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

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()

Use readAllSync() from the Standard Library instead.

+ import { readAllSync } from "https://deno.land/std/io/read_all.ts";

...

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

See deno#9795 for details.

Deno.readAll()

Use readAll() from the Standard Library instead.

+ import { readAll } from "https://deno.land/std/io/read_all.ts";

...

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

See deno#9795 for details.

Deno.Reader

Use Reader from the Standard Library instead.

+ import type { Reader } from "https://deno.land/std/io/types.ts";

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

See deno#9795 for details.

Deno.ReaderSync

Use ReaderSync from the Standard Library instead.

+ import type { ReaderSync } from "https://deno.land/std/io/types.ts";

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

See deno#9795 for details.

Deno.readSync()

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()

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()

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()

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()

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()

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

Use Deno.HttpServer instead.

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

See deno#20840 for details.

Deno.shutdown

Use Deno.Conn.closeWrite() instead.

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

See Deno 1.40 blog post for details.

Deno.stderr.rid

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

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

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

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

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

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()

Use writeAllSync() from the Standard Library instead.

+ import { writeAllSync } from "https://deno.land/std/io/write_all.ts";

...

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

See deno#9795 for details.

Deno.writeAll()

Use writeAll() from the Standard Library instead.

+ import { writeAll } from "https://deno.land/std/io/write_all.ts";

...

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

See deno#9795 for details.

Deno.Writer

Use Writer from the Standard Library instead.

+ import type { Writer } from "https://deno.land/std/io/types.ts";

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

See deno#9795 for details.

Deno.WriterSync

Use WriterSync from the Standard Library instead.

+ import type { WriterSync } from "https://deno.land/std/io/types.ts";

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

See deno#9795 for details.

Deno.writeSync()

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()

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()

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

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