Creating express backend application in Workers

I have an existing backend application which I am trying to recreate on workers. In my current application I am using express, sequelize and postgress. While recreating the application should I use these frameworks or are there any suggested alternatives that work better with workers?
10 Replies
conqr
conqr6mo ago
Itty-router is pretty good for express oriented backends
conqr
conqr6mo ago
GitHub
GitHub - kwhitley/itty-router: A little router.
A little router. Contribute to kwhitley/itty-router development by creating an account on GitHub.
conqr
conqr6mo ago
A major caveat is that instead of building up a response over multiple middlewares and routes, instead you build up a request and then whichever middleware / route returns a Response first, the chain ends It is possible to do some global middleware before a response is returned at router level, but you're mostly limited to modifying response metadata unless you with to reconstruct the response from scratch Sequelize probably won't work Postegres will work if you route it through cloudflare hyperdrive Otherwise, a new postegres connection will be made on every request (and destroyed) And it won't scale well Hyperdrive instead pools connections in each region, so you will have 100 concurrent connections maximum at any given time
anureddy11
anureddy116mo ago
Thanks @conqr . This is really helpful! One follow up question. So if Sequelize does not work, is there an alternate ORM or should I look to directly write SQL queries? Thanks in advance
conqr
conqr6mo ago
There are probably some, but many ORMs directly connect to the database, so it probably wouldn't work I recommend just writing SQL Cloudflare has a built-in SQLite Database for Workers named D1 I recommend testing / developing using that and then you can swap out to Hyperdrive for production Cloudflare workers have poor (or nonexistent) TCP support
anureddy11
anureddy116mo ago
Great. Will do exactly that!
conqr
conqr6mo ago
Also you need to keep in mind that Workers use a modified JS v8 runtime, and not the node runtime, so a lot of node packages need to be pollyfilled / don't work
conqr
conqr6mo ago
Cloudflare Docs
Node.js compatibility · Cloudflare Workers docs
Implemented Node.js runtime APIs and enablement instructions for your Worker project.
anureddy11
anureddy116mo ago
Ah yeah. Been encountering this!
conqr
conqr6mo ago
Generally, if some code / package doesn't work in the browser, it'll need to be pollyfilled / won't work at all on workers
Want results from more Discord servers?
Add your server