Add a New Deno Project

Supported Features

Because we are using an Nx plugin for Deno, all the features of Nx are available.

✅ Run Tasks ✅ Cache Task Results ✅ Share Your Cache ✅ Explore the Graph ✅ Distribute Task Execution ✅ Integrate with Editors ✅ Automate Updating Nx ✅ Enforce Module Boundaries ✅ Use Task Executors ✅ Use Code Generators ✅ Automate Updating Framework Dependencies

Install the Deno Plugin

Have Deno already installed?

Make sure you have Deno installed on your machine. Consult the Deno docs for more details

npm i --save-dev @nx/deno

Nx 15 and lower use @nrwl/ instead of @nx/

Create an Application

Directory Flag Behavior Changes

The command below uses the as-provided directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the derived option, omit the --directory flag. See the workspace layout documentation for more details.

Use the app generator to create a new Deno app.

nx g @nx/deno:app deno-app --directory=apps/deno-app

Nx 15 and lower use @nrwl/ instead of @nx/

Serve the API by running

nx serve deno-app

This starts the application on localhost:4200 by default.

Create a Library

Directory Flag Behavior Changes

The command below uses the as-provided directory flag behavior, which is the default in Nx 16.8.0. If you're on an earlier version of Nx or using the derived option, omit the --directory flag. See the workspace layout documentation for more details.

To create a new library, run:

nx g @nx/deno:lib my-lib --directory=libs/my-lib

Nx 15 and lower use @nrwl/ instead of @nx/
Deno Library Paths

Deno library paths are maintained in the root import_map.json file. Because typescript doesn't understand how to parse this file, you may get errors in your code editor that are not problems during build or serve.

Once the library is created, update the following files.

libs/my-lib/src/lib/my-lib.ts
1export function someFunction(): string { 2 return 'some function'; 3} 4
apps/deno-app/src/handler.ts
1import { someFunction } from '@my-org/my-lib'; 2 3// deno-lint-ignore require-await 4export async function handler(_request: Request): Promise<Response> { 5 const message = JSON.stringify({ 6 message: 'Hello deno-app ' + someFunction(), 7 }); 8 return new Response(message, { 9 status: 200, 10 headers: { 11 'content-type': 'application/json', 12 }, 13 }); 14} 15

Now when you serve your app, you'll see the content from the library being displayed.

More Documentation