Skip to main content
On this page

Making a Deno project

In this guide, you'll create your first Deno project, run it, and execute its tests. We'll use TypeScript throughout. To follow along in JavaScript instead, rename the files to .js and remove the type annotations.

Initialize a new project Jump to heading

To initialize a new Deno project, run the following command in your terminal:

>_
deno init my_project

This will create a new directory called my_project with the following structure:

my_project
├── deno.json
├── main_test.ts
└── main.ts

deno.json holds your project configuration. main.ts is a small HTTP server built on Deno.serve, and main_test.ts has the tests for it.

Run your project Jump to heading

Move into the new project directory:

>_
cd my_project

You can run this program with the following command:

>_
$ deno -N main.ts
Listening on http://localhost:8000/

The server needs network permission, granted here via -N (short for --allow-net). See security for more.

Open the URL in your browser to see the response.

Run your tests Jump to heading

Run the tests with deno test:

>_
$ deno test
running 2 tests from ./main_test.ts
handler returns hello ... ok (1ms)
handler returns 404 for unknown route ... ok (1ms)

ok | 2 passed | 0 failed (3ms)

Browse our examples and tutorials for ideas on what to build next.

Last updated on

Did you find what you needed?

Privacy policy