Ahmed Hammad
Ahmed Hammad

Reputation: 3085

Is Deno scripts compatible with Node.js?

I understand that most of npm packages are not compatible with Deno.js due to using require(), at least the ones not in deno.land/x.

But is the opposite possible? Can a Deno.js script be used in a Node.js project?

If yes, then how to convert the URL script into a node_modules package?

Upvotes: 2

Views: 1037

Answers (1)

Evandro Pomatti
Evandro Pomatti

Reputation: 15124

The opposite would have similar constraints.

The only practical way that a script can run on both Deno and Node.js, without pain and without adapting the code, is that if uses plain JavaScript.

Suppose you want to build a portable app to run on both Node.js and Deno:

  • In short, standard libraries are not portable, so you'll have to rely on portable external libraries, or modularizing your app so that you can plug in the components. Imagine dealing with that.
  • 3rd-party libraries must also be portable. A lot of Deno libraries, if not most, are written in TypeScript.
  • For practical reasons you'll have to choose JavaScript over TypeScript. Why impose such restriction if one wants to use TypeScript and get benefits of it? Also the Deno community is very strong with TypeScript.

A system in the real world cannot scale with these restrictions.

Upvotes: 1

Related Questions