NodeJS projects to Deno projects
I just recently found out about Deno and I already have used NodeJS in other projects and most clones of projects in github and such also use NodeJS
The point is that I want to have the forks/clones but using Deno instead
While I can't clone/fork them with a Deno version I will have to change it manually for compatibility purposes
Is there any important features that I should be aware of before trying out?
:deno_logo: :deno_logo: :deno_logo:
-# for example:
-# having to use deno.json or smth and remove package.json
An idea got but it's rather complicated and not acceptable in the guidelines of #ideas is for a CLI command like
deno nodeToDeno or smth with an argument which can be the path that it will check on which it could read nodeJS exclusive code and log it with an alternative for compatibility purposes
I think that's all I need to say
Feel free to ask me smth if you don't understand19 Replies
Deno is compatible with Nodejs. what you should do is just adding deno.json and type
Go to cmd and type
If you want to port Nodejs code to Deno, yes - you have to do all of that manually
I want to know code related stuff that I should change for deno
Like replace commonjs module system with es6's
you have to add ".ts" to end of each import local code.
like
to
What if I use JavaScript (js) or Express (ejs) or JavaScript XML (jsx)
then add extension name
like
Check this: https://docs.deno.com/runtime/reference/cli/unstable_flags/
sloppy import suppports importing without extension. but it doesn't support compile and it is unsafe feature 🙁
Deno
Unstable feature flags
In-depth documentation, guides, and reference materials for building secure, high-performance JavaScript and TypeScript applications with Deno
Ok
Any other stuff I should change in code for deno compatibility
-# not using nodeJS
You mean you want to replace all Nodejs functions to Deno?
like writeFile of Nodejs to Deno.writeFile ?
Pretty much
I just want to overall make it use deno so I can use a newer and fresher runtime instead of an older one
-# see want I did there😏
I just finished porting an entire codebase from nodejs to deno
2 frontends, 1 backend, 5 packages
You'll have to update import file extensions like veodium said
you have to check if all the libs you're working with is working fine. any libs that manage binaries or external stuff needs to be tested like Prisma ORM, @aws-sdk*, googleapis, etc
one very good i can say: you can clean all the garbage that comes with nodejs (biome, eslint, prettier, tsc, esbuild, swc, vitest, jest etc)
deno have everything you need by default
And how do I do that?
If you mean smth other than files manually added to work with like TS config
all you need is deno.json
so I format, check(?), lint, bundle, compile and test?
could you give me an explanation as of why these particularly and what does check do?
prints all warnings and type errors
you can format all your files with
i'm tired of typing, you can read the docs for the CLI https://docs.deno.com/runtime/reference/cli/check/
deno fmt just like prettier
you can manage its defaults at deno.json -> "fmt"
deno check does type checking just like tsc, you can configure its defaults at deno.json -> "compilerOptions"
deno lint (eslint, biome) will blame bad patterns based on rules defined at deno.json -> "lint"i'm tired of typing, you can read the docs for the CLI https://docs.deno.com/runtime/reference/cli/check/
Check does the same as tsc --noEmit
I know everyone said "manually" but actually I made a tool that does 90% automatically. It converts imports/exports/require makes sloppy imports non-sloppy (e.g. adds .js .ts and handles importing a folder as index.js/.ts), adds prefixes for node: and npm: and adds FIXME for stuff like dynamic imports that it can't handle:
https://github.com/jeff-hykin/to-esm/
It uses deno tree sitter (another library I maintain) to do actual parsing (not regex) over the codebase.
GitHub
GitHub - jeff-hykin/to-esm
Contribute to jeff-hykin/to-esm development by creating an account on GitHub.
So you went through the process of making automatic module system upgrade?
Cool
Thanks! Yeah I don't use a library unless I can either import it with esm.sh (auto converts code much more reliably than my to-esm but its messy/compiled) or import it with relative imports. So after manually converting ~12 codebases I got pretty tired of doing everything manually