Node 12 | Reference error: FinalizationRegistry is not defined - node.js

I am trying to host a node js (express) at dream host using shared unlimited plan. I was able to do most of the work. There is only one problem, dreamhost uses passenger to run node js app, and passenger does not support node 14+, so I have to stick with node v12.
The express js project I was building is built on typescript and I used node v16 to do all of the stuff installing, running etc. When I build the typescript, it uses an npm package exit-free-leak which uses FinalizationRegistry, hence requires node v14+.
So after building the app, When I run the app.js with node v12 it gives me the error that FinalizationRegistry is not defined. For now I am getting this error, but the exit-free-leak uses another node v14+ function "WeakRef".
So my question is how do I get around this issue while using node v12 ? is there anyway to polyfill these functions or disable use of the package exit-free-leak using tsconfig.json, or maybe an even better solution.

Unfortunately the answer to "how do I get around this issue while using node v12" is probably: "you don't".
Node 12 has been end-of-life for 9 months; given how fast the JavaScript ecosystem moves in general, it's unlikely that libraries will keep supporting that version for very long anyway.
You'd be best off asking Dreamhost about Node 16 or 18 support, or move elsewhere if they can't provide you with up-to-date runtimes that still get security updates.

Related

React application developed using node JS v10

I have a main react application in which many other react applications have been developed. This was developed way before I joined. However, this is bothering me , because react applications keep coming in, and technically we keep building using nodejs10 to each new application.
Iam overthinking ?, or something can happen in the future
Can this be supported by node js?
I also considered updating all applications to the latest nodejs. But I'm fearful of the damages or if this idea is even feasible to implement?
From my personal experience, it's quite rare for a Node upgrade to break a React build.
But it all depends on the complexity of the app and the packages used and how old are the dependencies.
I wouldn't say you're overthinking, Node 10 support ended at the end of April so it would be advisable to upgrade to a more recent version.
I would ask the relevant person to have a couple of days to tackle the tech debt and try to upgrade Node to 16.
If you are using nvm you could switch to Node 16 using the --reinstall-packages-from command targeting your current version and try to build.
It's going to take you a couple of minutes.
You can always switch back to 10 with a single command.

crypto.getCurves is undefined

I am trying to use an oauth helper library called 'openid-client'. I am getting an error that reads in part '(TypeError): getCurves is not a function'. I poke around and find that getCurves is part of an inbuilt module of node.js 'crypto'.
If I console.log(typeOf(crypto.getCurves)) I get undefined. If I console.log(crypto) I see that crypto has many available methods but getCurves is not among them.
I am running node on my macbook and my project is a barebones npx create-react-app app with openid-client installed.
The node documentation outlines a way for determining if crypto support is unavailable, but that does not seem to indicate that crypto is unavailable for me.
I'm not sure why my version of node crypto does not have getCurves. Is there a way to install the correct version? Is there some sort of encryption restriction I am hitting due to OS? Any help appreciated.
node-openid-client is using APIs which are provided by Node and are missing in browser.
Node is being used by CRA as a development tool. App itself is running in browser and can't access Node's API-s, so it doesn't matter which Node version CRA is using.
When built, app is a set of JS files which can be served by a webserver (such as Nginx) directly without using Node at all.
So, this library can't be used with CRA apps.
https://github.com/panva/node-openid-client/issues/218
As you said, crypto is a built-in module, which means that its functionality depends on the version of node.js you have installed (you can check it via node -v from the shell or via console.log(process.version) at runtime).
Node.js API docs say that getCurves() was added in v2.3.0, so make sure your node is more recent than that.

How to verify node.js version (other than node -v)

I have this strange issue, where I am using 10th version of node (10.9.0) on a server, but things that should work or be supported in that version, are not.
For example, according to this table, this version supports Object.values(). On my local node installation - this indeed works, but on server, where I don't have much freedom about what software I am using, it does not.
Is there any way to truly verify used node version (node -v shows 10.9.0 as written above)? Maybe it's only a version of main binary yet all libs it's using are from version 6 (that one is also installed on that server)?
The process object that Node.js exposes has a lot of information including the version.
console.log(process.version); // v10.9.0
You can find the Node.js process.verison documentation here.
So within your application you can run that to see if it's truly what you expect.
You can also try running which node on your server. That should print the path it's using to find node. If you have multiple copies or installations of node, it might be using a path that is outdated. Making sure your path is up to date will solve that problem, and which node can help debug that.

What are all the functions that can be done using node js?

I am a node js beginner.. I have done several services in node js like insert/update/delete/e-mail using SMTP/chat using socket.. i would like to know about what else can be done using node js.
Here's documentation for all the stuff node comes with:
https://nodejs.org/en/docs/
https://nodejs.org/api/
But that's barely it. Node's used widely due to the variety of packages written for it. Check out Node Package Manager (npm): https://www.npmjs.com/
As you can see, there are ~400,000 packages. Of course, the ones you're gonna be using depend on your requirement.
Some starting packages you should look at:
Express—Web framework.
Mongoose—Database interface

Fabric.js on Node 4+

It seems to be a known issue that Fabric.js will fails to install out of the box on node.js >=4.
Is it possible to make it work on node >=4? And if not, is there a way to still use it on a node >=4 app, or does the fact that fabric itself only works on node <4 forces me to write my whole app in <4 as well?
Is it possible to two separate versions of node simultaneously, using v0.12 just to run the fabric module, and v4+ for the app itself? Is this approach even worth investigating?

Resources