deno init, start a new project
Command line usage
deno init [OPTIONS] [DIRECTORY OR PACKAGE]...scaffolds a basic Deno project with a script, test, and configuration file
Options Jump to heading
--lib Jump to heading
Generate an example library project.
--npm Jump to heading
Generate a npm create-* project.
--serve Jump to heading
Generate an example project for deno serve.
Examples Jump to heading
$ deno init
✅ Project initialized
Run these commands to get started
  // Run the program
  deno run main.ts
  // Run the program and watch for file changes
  deno task dev
  // Run the tests
  deno test
$ deno run main.ts
Add 2 + 3 = 5
$ deno test
Check file:///dev/main_test.ts
running 1 test from main_test.ts
addTest ... ok (6ms)
ok | 1 passed | 0 failed (29ms)
The init subcommand will create two files (main.ts and main_test.ts).
These files provide a basic example of how to write a Deno program and how to
write tests for it. The main.ts file exports a add function that adds two
numbers together and the main_test.ts file contains a test for this function.
You can also specify an argument to deno init to initialize a project in a
specific directory:
$ deno init my_deno_project
✅ Project initialized
Run these commands to get started
  cd my_deno_project
  // Run the program
  deno run main.ts
  // Run the program and watch for file changes
  deno task dev
  // Run the tests
  deno test
Init a JSR package Jump to heading
By running deno init --lib Deno will bootstrap a project that is ready to be
published on JSR.
$ deno init --lib
✅ Project initialized
Run these commands to get started
  # Run the tests
  deno test
  # Run the tests and watch for file changes
  deno task dev
  # Publish to JSR (dry run)
  deno publish --dry-run
Inside deno.json you'll see that the entries for name, exports and
version are prefilled.
{
  "name": "my-lib",
  "version": "0.1.0",
  "exports": "./mod.ts",
  "tasks": {
    "dev": "deno test --watch mod.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}
Initialize a web server Jump to heading
Running deno init --serve bootstraps a web server that works with
deno serve.
$ deno init --serve
✅ Project initialized
Run these commands to get started
  # Run the server
  deno serve -R main.ts
  # Run the server and watch for file changes
  deno task dev
  # Run the tests
  deno -R test
Your deno.json file will look like
this:
{
  "tasks": {
    "dev": "deno serve --watch -R main.ts"
  },
  "imports": {
    "@std/assert": "jsr:@std/assert@1",
    "@std/http": "jsr:@std/http@1"
  }
}
Now, you can start your web server, which
watches for changes,
by running deno task dev.
$ deno task dev
Task dev deno serve --watch -R main.ts
Watcher Process started.
deno serve: Listening on http://0.0.0.0:8000/
Generate a library project Jump to heading
You can append a --lib flag to add extra parameters to your deno.json, such
as "name", "version" and an "exports" fields.
$ deno init my_deno_project --lib
✅ Project initialized
The resulting `deno.json will be as follows:
{
  "name": "my_deno_project",
  "version": "0.1.0",
  "exports": "./mod.ts",
  "tasks": {
    "dev": "deno test --watch mod.ts"
  },
  "license": "MIT",
  "imports": {
    "@std/assert": "jsr:@std/assert@1"
  }
}