Cloudflare Workers integration is now possible

Today, Cloudflare announced their support for TCP sockets in Workers, along with day-1 support for Postgres.

I would love to see some form of first class support, either in the main package or through another package, but I can’t think of a good way to do this (aside from forking the Node driver). I took a look at Postgres’ solution here; they check if net.Socket exists, otherwise the Cloudflare implementation is used instead. Seems straightforward, there might be a more elegant way to make that check.

What are other peoples’ thoughts on this? Would something like this be worth a pull request?

1 Like

Hey @Cole_Crouter, I’m the Product Manager for the Node.js Driver so I’d be happy to chime in here.

Our engineers provided early feedback on the Socket API design, however we have not yet completed a review of the final product Cloudflare released this week.

This is something we are reviewing in detail and plan to share more information on as we progress. We always welcome feedback and participation from the developer community, so if you have ideas either open a ticket in our Jira under the NODE project or continue to ask questions here on our forums.

Hi @alexbevi - that sounds very interresting :nerd_face:

Any updates on this project? Would be amazing to be able to connect to MongoDB from a Cloudflare worker (without having to use a slow HTTP API or data proxy).

1 Like

Hi @Alex_Bjorlig, and apologies for the delay in getting back to you.

Cloudflare Workers aren’t 100% API compatible with Node.js, though they do offer a nodejs_compat compatibility flag to improve this developer experience.

The MongoDB Node.js Driver leverages a number of Node.js APIs internally, which our team found during preliminary testing weren’t compatible with Cloudflare Workers (even using nodejs_compat).

We are working on improving this as it currently prevents users from using the MongoDB Node.js Driver in this environment at all. Once we have this functional and understand the implications for our developers we’ll have more information to share.

1 Like

No worries :pray:

We are deployed with Vercel, and are slowly and steadily preparing our application for the edge. Because we use MongoDB, this is a critical step of the journey.

We expect the edge to make the app faster, as we won’t have cold starts (and getting closer to the end-user for non-data interactions)

You can always reach out if you need someone to test initial iterations or similar. (And if we can help in other ways, please let us know :nerd_face:)

Também estamos esperando isso para trazer todos nossos bancos de dados para a MongoDB.