nodeJS application not running in cloudflare worker

For Workers & Pages, what is the name of the domain?

What is the error message?

Unexpected external import of “fs”, “http”,

What is the issue or error you’re encountering

I am using nodejs 17.9.1 version and created the application now I want to host the application to cloudflare worker.

What steps have you taken to resolve the issue?

I tried to add the compatibility flags in wrangler.jsonc file.
{
“$schema”: “node_modules/wrangler/config-schema.json”,
“name”: “my-worker”,
“main”: “./server.js”,
“compatibility_date”: “2024-12-05”,
“compatibility_flags”: [
“nodejs_compat”,
“nodejs_als”
]
}

What are the steps to reproduce the issue?

the github url for the project: GitHub - athempeed/cloudflareworker
download it and run locally
run command npx wrangler dev/deploy in command prompt

Screenshot of the error

Workers don’t run Node.js directly, so you will not have access to things like a filesystem with fs, nor will you be able to “listen” on a specific IP/port like you do in Node.js. You can handle requests via the fetch handler: Fetch Handler · Cloudflare Workers docs

There is some Node.js compatibility which you can read about here:

but not everything is supported.

Looking at your project, it seems like you’re trying to serve some static files and that’s about it? Have you considered Workers Assets for this?

1 Like

Thank you so much for the reply. its just a test . I want to use liquid JS along with node to support a template based system. so my idea is to have a template pages and worker would pick those pages and run the page with changes dynamically given to it.
the pages would create in liquid js and using node I would change the template things like headings and all which will run inside worker.
let me try to look into fetcher.