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 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
❯
nx add @nx/deno
Create an Application
Directory Flag Behavior ChangesThe 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 as-provided vs. derived 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
Serve the API by running
❯
nx serve deno-app
This starts the application on localhost:4200 by default.
Create a Library
Directory Flag Behavior ChangesThe 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 as-provided vs. derived documentation for more details.
To create a new library, run:
❯
nx g @nx/deno:lib my-lib --directory=libs/my-lib
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.
1export function someFunction(): string {
2 return 'some function';
3}
4
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.