A module to run Deno scripts from Node.js, including functionalities for downloading Deno and executing Deno scripts.
Go to file
2024-05-29 14:12:35 +02:00
.gitea/workflows fix(core): update 2024-03-17 00:53:32 +01:00
.vscode fix(core): update 2024-03-17 00:53:32 +01:00
assets fix(core): update 2024-03-17 21:24:25 +01:00
test fix(core): update 2024-03-17 21:24:25 +01:00
ts fix(core): update 2024-03-17 21:24:25 +01:00
.gitignore fix(core): update 2024-03-17 00:53:32 +01:00
npmextra.json update tsconfig 2024-04-14 17:29:06 +02:00
package.json update description 2024-05-29 14:12:35 +02:00
pnpm-lock.yaml fix(core): update 2024-03-17 21:24:25 +01:00
readme.hints.md update tsconfig 2024-04-14 17:29:06 +02:00
readme.md update tsconfig 2024-04-14 17:29:06 +02:00
tsconfig.json fix(core): update 2024-03-17 00:53:32 +01:00

@push.rocks/smartdeno

a module to run deno from node

Install

To install @push.rocks/smartdeno, run the following command in your project directory:

npm install @push.rocks/smartdeno --save

Usage

This guide will provide an overview of how to use @push.rocks/smartdeno in your Node.js project to run Deno scripts. Given the nature of the project, which allows running Deno from Node.js environments, we'll explore various scenarios including setup, executing a simple Deno script, integrating with existing Node.js workflows, and managing Deno downloads.

Setting Up

First, ensure you import SmartDeno in your TypeScript file using the ESM syntax:

import { SmartDeno } from '@push.rocks/smartdeno';

Initializing SmartDeno

To start working with Deno in your Node.js project, you first need to create an instance of SmartDeno and start it. This process prepares the environment, including downloading Deno if necessary:

const smartDeno = new SmartDeno();

async function setup() {
  await smartDeno.start({
    forceLocalDeno: true // Use this to force a local download of Deno even if it's globally available
  });
}

setup();

Executing a Deno Script

With SmartDeno set and started, you can now execute Deno scripts. Let's run a simple script that prints a message:

async function runDenoScript() {
  const script = `console.log("Hello from Deno!");`;
  await smartDeno.executeScript(script);
}

runDenoScript();

This method sends the script to Deno for execution. The flexibility of SmartDeno allows for more complex scripts to be executed similarly.

Integrating with Node.js Workflows

SmartDeno can be seamlessly integrated into existing Node.js applications or workflows. Here's an example of integrating a Deno script execution within a Node.js Express server:

import express from 'express';
const app = express();
const port = 3000;

app.get('/run-deno-script', async (req, res) => {
  const script = `console.log("Deno script executed!");`;
  await smartDeno.executeScript(script);
  res.send('Deno script executed. Check console for output.');
});

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`);
});

Managing Deno Version

To manage which Deno version SmartDeno uses, the setup step allows for specifying forceLocalDeno. If you need to use a specific version of Deno, you can customize the download process by extending or modifying the download logic in classes.denodownloader.ts.

Stopping SmartDeno

When your application is done using Deno, or if you need to clean up resources, you can stop the SmartDeno instance:

async function teardown() {
  await smartDeno.stop();
}

teardown();

Conclusion

@push.rocks/smartdeno provides a powerful and simple pathway for Node.js applications to run Deno scripts, combine the strengths of both environments, and leverage Deno's features within Node.js projects. Whether it's for executing isolated scripts, taking advantage of Deno's security model, or using Deno modules, SmartDeno offers the tools necessary for seamless integration.

For further information and advanced use cases, refer to the official GitHub repository and the typed documentation linked at the top of this guide.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.