Top 3 New Node.js APIs on Cloudflare Workers
Chapters5
This chapter introduces Confidence’s top three new Node APIs available on Cloudflare Workers and notes that the picks are biased toward the author’s preferences, with something for a wide range of users.
Cloudflare Developers’ Confidence shows off three game-changing Node.js APIs on Cloudflare Workers: HTTP/HTTPS server and client models, an in-memory FS, and the process API with environment access, plus zlib compression support.
Summary
Confidence from Cloudflare Developers presents a practical tour of the top new Node.js APIs now available on Cloudflare Workers. He kicks off with HTTP and HTTPS client/server models, noting that popular libraries like Express should run without issue inside a Worker. Next, he demonstrates an in-memory Node FS model that lets libraries read and write temporary files within the ephemeral, serverless environment. The process API follows, enabling access to environment variables and standard streams (stdin, stdout, stderr) with logs visible in the Dashboard. He also briefly introduces zlib-based compression for data packaging and transmission. Throughout, Confidence emphasizes compatibility with existing Node.js libraries and the ability to run familiar server-side code inside Cloudflare Workers. He ends by pointing to the blog for more APIs and invites developers to share what they build. This makes a compelling case for expanding what you can do with Workers using familiar Node.js tooling, without migrating away from the platform.
Key Takeaways
- Node HTTP/HTTPS server and client models are now supported in Cloudflare Workers, enabling libraries like Express to run inside a Worker.
- An in-memory, ephemeral Node FS model is available so libraries relying on a file system can create and read files within a Worker without a traditional disk.
- The Node process model brings environment variables and standard streams (stdin, stdout, stderr) into Workers, with logs captured in the dashboard.
- Zlib-based compression (node-zlib) is supported, allowing compression and decompression of data within Workers for efficient transmission.
- Several honorable mentions are highlighted for broader Node API support: DNS, TLS sockets, crypto, timers, and console APIs on Cloudflare Workers.
Who Is This For?
Essential viewing for developers building on Cloudflare Workers who want to run broader Node.js ecosystems by reusing familiar APIs and libraries without sacrificing the serverless edge benefits.
Notable Quotes
""The first node API I'm going to be showing you is support for the node HTTP and HTTPS client and server models.""
—Introduces the HTTP/HTTPS API support and its impact on libraries like Express.
""This is now available on Cloudflare workers and client libraries who depend on stuff like HTTP get or HTTP request should work just fine.""
—Emphasizes compatibility with existing HTTP client usage.
""We have implemented an in-memory virtual file system based on a node FS model that is ephemeral.""
—Explains the FS model as a temporary, in-memory solution for Worker environments.
""The process model is another fundamental API available on node and that's because several libraries depend on having access to the process model.""
—Highlights why process API matters for environment access and libraries.
""This is also cool because it's going to unlock new use cases for your worker applications.""
—Describes the practical benefits of adding these node APIs, including compression and broader library support.
Questions This Video Answers
- How do I run Express apps inside Cloudflare Workers with the new Node HTTP/HTTPS models?
- Can I read and write temporary files in Cloudflare Workers using the new Node FS model?
- How does the Node process API expose environment variables in Cloudflare Workers?
- What are the benefits of zlib compression in Cloudflare Workers and how do I implement it?
- Which Node.js APIs are supported on Cloudflare Workers beyond HTTP, FS, and process models (e.g., DNS, TLS, crypto)?
Cloudflare WorkersNode.js APIsHTTP/HTTPS client/serverNode FS modelNode process modelEnvironment variablesZlib compressionExpress on WorkersDNS in WorkersTLS sockets on Workers
Full Transcript
[Music] Hey guys, welcome back to the channel. In this video, I'm going to show you my top three new favorite node APIs that is available on Cloudflare Workers. Of course, this is going to be a slightly biased list because it's based on my preference, but I'm sure there's something in here for everyone. My name is Confidence and I am a developer advocate at Cloudflare. Without any delay, let's get started. The first node API I'm going to be showing you is support for the node HTTP and HTTPS client and server models. This is a highly requested node API and that's because lots of libraries depend on the nodes HTTP and HTTP models.
So this is now available on Cloudflare workers and client libraries who depend on stuff like HTTP get or HTTP request should work just fine also which is really cool server libraries dependent on these APIs for creating HTTP servers or HTTPS servers should work as well on Cloudflare which is awesome. So I'm going to show you a demo right here. Um what I have on screen is the create server model from the node HTTP uh library and you can see I'm creating a server and um returning it. So I have this running and if we go to the browser to check this out.
So this should be for/ HTTP. Uh you can see that we are running a HTTP server inside of uh Cloudflare workers. We have that model supported inside of Cloudflare Workers. But what I think is really cool about this is that node server libraries should work just fine. Like mpm libraries, server libraries should work just fine. Things like express or ka should work just fine. And I have a demo of that. This is expressjs. All right. So I have express installed of course and I have a route here that uh just prints out the text express running in cla workers and we have that exported here as well.
So if I go to the browser and let's take a look at express you see that we have that text returned saying express running in cloudflare worker. So with this new addition you can go use any of your favorite NodeJS server libraries and it should work just fine. I think this is really cool. Moving on to the second API that I'm excited about is the support for the node FS model. Adding support for the node FS model has been particularly tricky because the worker's runtime is in a serless environment and also a deployed worker lives in everywhere on cloudless network that's over 300 plus cities.
So there's that insane engineering complexity of trying to keep the local file system of a worker in sync with every other location where it is deployed and then doing that for every single worker that has been deployed. That that's like crazy. So implementing a traditional file system would not be the solution here. And that's why we created durable objects. If you need to coordinate state across multiple workers, you reach out for durable objects. It handles states really well. But what we've done here is that we have implemented an in-memory virtual file system based on a node FS model that is ephemeral.
Ephemeral being the key word here because the workers runtime is a serverless environment. But what this allows you to do is that it enables libraries dependent on the node FS model to work smoothly inside of Cloudflare workers. So libraries that require or depend on the file system to create uh temporary configuration files to do their work. All of that should run smoothly on cloudfare workers. So let me show you what that looks like. I am going to head back to my uh editor and let's open the FS. All right, this is this is the FS implementation.
So you can go ahead to go import the node FS model and of course you can create a file as you can see. So we've created a configuration file uh a JSON file and we can read the contents of the file and do whatever we want to do with it. For instance, just return it as the response. So I can head back to the browser and let's take a look at FS. All right. And you can see that this returns the JSON is cool true because the node FS model is really cool. So yeah, this is supported on Cloudflare workers and you should be able to create files and read files in memory using the FS model.
The next API I am excited about is the process model which also has support for the environment variables. The process model is another fundamental API available on node and that's because several libraries depend on having access to the process model to do lots of things like to read things like the environment variable for instance if a library needs to read some content from the environment or to read information about the node process it is running in. So things like process should work out of the box with this new support. We've also added like process the std in, std out or standard error.
Um, writing to any of these will create logs that are captured in the dashboard. So, you'll be able to see them on the dashboard and that's really cool. Um, one cool addition with this is that having access to the environ to the process makes it such that you can access the environment on the top level of your worker or actually on any scope of your worker like literally anywhere. Let me show you what I mean. So, let's head to the um my editor and let's go open process. Oh, this should process. All right, that's process.
And if you take a look at this, we're importing process from node. And this is something that's really cool about it. You can now read the environment variable from the top level or on any scope in your file. So I've created an environment variable file. Um I created an env file and this has the content full bar and we can read that content from the environment. But this does not also stop you from using the env parameter to the fetch function. You can also use that as well and it's just going to work as you have expected.
And what I'm doing here is just uh stringifying content in the process. So we can go to the browser and check out process. And this is the content of the process. And you can see we are also able to read the content of the environment variable which is cool. So libraries depending on the process model that needs to read information about your environment. Of course, this is not a node environment. This is a workers environment. Uh this should be supported. So those libraries would not break and they have access to the node APIs they need to run.
All right. So I'm going to do the one more thing and squeeze in an extra API that we have supported. I'm also excited about and that's compression in workers using the zed lib or node z lib or in US node zip uh model. So the zed model provides algorithms such as the flate gzip and broley for compressing and decompressing data. It's now supported on workers and libraries or yeah libraries depending on it should work just fine. But this is also cool because it's going to unlock new use cases for your worker applications. You're going to be able to properly handle archives using this libraries and you can also do things like uh compressing data for network transmission.
Like if you need to send it somewhere, you can compress it before sending over and that would help to optimize the speed of your application. This is what that looks like in the code. So let's open up uh ZLIB. All right. You can import that from the node uh z lib library and you can create a compression give it some data get that compressed you have your archive you can decompress it and of course you can return that to wherever it's needed so we can take a look at this in the browser zib and you can see that we have the response saying hello from cloud workers and zed lib so this is awesome and of Of course, there are a lot more supported node APIs.
Um, a few honorable mentions are support for the node DNS model, which means that you are able to perform DNS queries inside of your Cloudflare worker. Support for the Node and Node TLS model to create TCP and TLS sockets respectively inside of Cloudflare workers. Support for the node crypto API for hashing, encryption, and decryption. and also support for note timers and node console APIs on cloud for workers. There a lot more. I want you to take a look at the blog in the notes below so you can go check out this APIs and get started with them.
I'm really excited to see what you build using this new node APIs on Cloudflare workers and also the huge range of libraries, external libraries that are supported as a result of having these node APIs on cloudflare workers. So I would love to see what you build. Don't forget to get subscribed and I'll see you in the next one. Take care. Bye.
More from Cloudflare Developers
Get daily recaps from
Cloudflare Developers
AI-powered summaries delivered to your inbox. Save hours every week while staying fully informed.









