Skip to content

Commit

Permalink
Node-API addons (denoland#920)
Browse files Browse the repository at this point in the history
  • Loading branch information
bartlomieju authored Sep 30, 2024
1 parent e89157f commit c5a9af7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
18 changes: 18 additions & 0 deletions runtime/fundamentals/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,24 @@ subclasses instead.
- `__dirname` - use `import.meta.dirname` instead.
## Node-API addons
Deno supports [Node-API addons](https://nodejs.org/api/n-api.html) that are used
by popular npm packages like [`esbuild`](https://www.npmjs.com/package/esbuild),
[`npm:sqlite3`](https://www.npmjs.com/package/sqlite3) or
[`npm:duckdb`](https://www.npmjs.com/package/duckdb).
You can expect all packages that use public and documented Node-APIs to work.
:::info
Most packages using Node-API addons rely on npm "lifecycle scripts", like
`postinstall`. While Deno supports them, they are not run by default due to
security considerations. Read more in
[`deno install` docs](/runtime/reference/cli/install/).
:::
## Runtime permissions in Deno
Consider the following simple [Express](https://expressjs.com/) server:
Expand Down
22 changes: 22 additions & 0 deletions runtime/reference/cli/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ example installation command to your repository:
$ deno install -n awesome_cli https://example.com/awesome/cli.ts
```

## Native Node.js addons

A lot of popular packages npm packages like
[`npm:sqlite3`](https://www.npmjs.com/package/sqlite3) or
[`npm:duckdb`](https://www.npmjs.com/package/duckdb) depend on
["lifecycle scripts"](https://docs.npmjs.com/cli/v10/using-npm/scripts#life-cycle-scripts),
eg. `preinstall` or `postinstall` scripts. Most often running these scripts is
required for a package to work correctly.

Unlike npm, Deno does not run these scripts by default as they pose a potential
security vulnerability.

You can still run these scripts by passing the `--allow-scripts=<packages>` flag
when running `deno install`:

```shell
deno install --allow-scripts=npm:sqlite3
```

_Install all dependencies and allow `npm:sqlite3` package to run its lifecycle
scripts_.

## Uninstall

You can uninstall dependencies or binary script with `deno uninstall` command:
Expand Down

0 comments on commit c5a9af7

Please sign in to comment.