I usually use the fcm-node
package for sending Firebase push notifications in Node.js. However, this time, I created a TypeScript project and encountered an error.
I am aware that in TypeScript, we need to install type definitions (@types) too. The problem is that when I run npm i @types/fcm-node, it gives me a 404 error. If I’m not mistaken, there are no TypeScript modules available for this package. How can I implement this in TypeScript? Does anyone know of any workarounds? I did try converting my notification.service.ts file to a .js file and used require instead of import in the TypeScript file. This approach worked for npm run dev, but after building with npm run build, when I run dist/index.js, it is unable to find my notification.service.js
So after trying a lot, in the end, it turns out that fcm-node doesn’t have types, and writing its type on my own will be a headache. I noticed on the npm website that it has a warning: the package is kind of deprecated because firebase-admin supports push notifications, so it’s better to use it. The only difference is that for fcm-node, we only require the API key, but for firebase-admin, it will require the google-service.json file.