Does Node Work With Cloudflare? Or What Is Your Recommended Way To Use Cloudflare?

Hey yall, I'm a very new web developer and I'm trying to just learn more about hosting and publishing sites. I've seen the speed that cloudflare workers offers in terms of API requests and feel it would be really cool to be able to host my backend requests on cloudflare to be handled. However, I generally develop in Javascript/NodeJS, thus my api routes are often some sort of router/handler (I saw hono seems to work well with cloudflare so I've been using it as of recently) and some logic in the route, generally for like a login system or something I prefer to use bcrypt's cryptography library for hashing/checking hashed passwords, however with trying to call a bcrypt function inside of the hono route, it works locally then when trying to push the app to cloudflare I get errors. Can cloudflare be used in any capacity with NodeJS and specifically packages? Or does all of my logic have to be written out directly in that route not importing a node module package or anything?
6 Replies
Rocky
RockyOP9mo ago
Because it seems that if things are required/imported properly cloudflare has some decent support for node's inbuilt libraries like node:fs, however for things like bcrypt is there any way at all to use this? Thank you in advance for any and all help, feel free to call me an idiot because from what I found online it defiantly can't work, however I'm holding out some hope I guess
neuner
neuner9mo ago
i use https://npm.im/bcryptjs on the edge
npm
bcryptjs
Optimized bcrypt in plain JavaScript with zero dependencies. Compatible to 'bcrypt'.. Latest version: 2.4.3, last published: 7 years ago. Start using bcryptjs in your project by running npm i bcryptjs. There are 3482 other projects in the npm registry using bcryptjs.
neuner
neuner9mo ago
i think you can get pretty much anything to work on the edge though * *(probably not fs - there's no filesystem) remix uses KV for files i believe
Rocky
RockyOP9mo ago
on the edge? I'm sorry I'm incredibly new to cloudflare and have only ever heard of workers, what do you mean by on the edge? I saw there were quite a few ways to deploy to CF and one of my teachers recommended Remix for publishing but I've never heard of edge and only once of Remix thank you for the recommendation and the assurance that it can work, just may be a little more complex than I'm thinking
stio_studio
stio_studio9mo ago
Workers can be strange to work with in the start as they are serverless just so you know it
neuner
neuner9mo ago
this also, as a result, has first-class support for web apis like crypto, fetch, Request/Response oddly, i was trying aws's sdk and it didn't play nice with workers, probably because the node package was intended for monolithic use (or with a full node installation)
Want results from more Discord servers?
Add your server