Skip to content

Conversation

@davidchase
Copy link
Contributor

Node.js 22 Runtime Environment with ESM Support

Summary

This PR introduces a separate directory for Nodejs 22 runtime env (server.js) with some dependency updates such as Pino logging instead of Morgan.

Resolves #277

New Features

Node.js 22 Environment

  • Dedicated directory: nodejs22/ with complete environment setup
  • Latest Node.js: Version 22.17.1 on Alpine Linux 3.22
  • ESM support: "type": "module" configuration enables native import/export syntax
  • Modern dependencies: Express 5.1.0, Pino logging, WebSocket support

ESM-Ready Examples

All examples use modern ESM syntax and Node.js 22 features:

Example Description Node.js 22 Features
hello.js ESM hello world ESM module with query params
weather.js HTTP requests demo Native fetch API, error handling
multi-entry.js Multiple endpoints Named exports, routing
broadcast.js WebSocket broadcasting Multi-client messaging with ws 8.18
kubeEventsSlack.js Kubernetes integration Event processing, webhooks

Usage

Environment Creation

# Create Node.js 22 environment
fission env create --name node22 --image davidchase03/node-env-22:v2.0.1

# With builder support
fission env create --name node22 --image davidchase03/node-env-22:v2.0.1 --builder node-builder-22

Function Deployment (ESM)

# Deploy ESM function
fission fn create --name hello-esm --env node22 --code hello.js

# Test with query parameters
fission fn test --name hello-esm
curl "$FISSION_ROUTER/hello-esm?name=World"

Modern Function Syntax

// ESM function
export default async function(context) {
    const { query } = context.request;
    return {
        status: 200,
        body: JSON.stringify({
            message: `Hello ${query.name || 'World'} from Node.js 22! 🚀`,
            nodeVersion: process.version
        }),
        headers: { 'Content-Type': 'application/json' }
    }
}

Breaking Changes

None - this is purely additive. Existing nodejs/ environment remains unchanged for backward compatibility.

Testing

  • All existing Node.js tests continue to pass
  • New Node.js 22 specific test cases in nodejs22/test/
  • ESM examples tested with Node.js 22.17.1 runtime

Benefits

  • Modern JavaScript: Native ESM, top-level await, latest syntax
  • Better Performance: Node.js 22 optimizations and faster startup
  • Developer Experience: Modern tooling, better error messages
  • Backward Compatible: Existing Node.js environment unaffected

@davidchase
Copy link
Contributor Author

@sanketsudake please let me know what else is needed to get the PR merged, it should include your changes from the #423 PR

@sanketsudake
Copy link
Member

sanketsudake commented Aug 12, 2025

@davidchase I was trying common js with ESM module, got following error.

./test/local_test.sh
-- Starting server
Fission Node.js 22 runtime listening on port 8888
-- Specializing
Loading user function from: ./test/test.js with function name: default
user code load error: ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/Users/sanketsudake/fission/environments/nodejs/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
curl: (22) The requested URL returned error: 500
{"level":30,"time":1755001637853,"pid":24454,"hostname":"Sankets-MacBook-Air.local","method":"POST","url":"/specialize","status":500,"duration":"6ms","userAgent":"curl/8.7.1","msg":"HTTP Request"}
-- Cleanup
Killing process 24454

So if possible I would consider following approach,

We merge your code with existing nodejs environment, mainly following files

	modified:   nodejs/package-lock.json
	modified:   nodejs/package.json
	modified:   nodejs/server.js

On test side we keep both common js and ES modules testcases and examples.

We can add an environment variable which tells environment if function is ESM or not.
Eg. LOAD_ESM=true/false

Based on ESM set or not we can support both ESM and traditional functions.

I am not sure if this possible, but if we can get something like this that would help current functions as well ESM functions.

We can even create docker images based by setting and unsetting ESM flag.

@davidchase
Copy link
Contributor Author

@sanketsudake so you dont want to keep separate runtimes envs? meaning those that need legacy support (cjs) would use one version of nodejs like nodejs18 and those using current features which include ESM would use nodejs22 image

@sanketsudake
Copy link
Member

sanketsudake commented Aug 12, 2025

So nodejs 18, we can deprecate totally and support node 22 and above only as its LTS now.

I am not expert in nodejs, but just trying to find middle ground so that we dont need to maintain multiple envs per language unnecessarily.

@davidchase
Copy link
Contributor Author

@sanketsudake i have made updates to the PR with LOAD_ESM env var and added to read me how to use with env flag --runtime-env

@sanketsudake
Copy link
Member

sanketsudake commented Aug 14, 2025

Can you please adjust all code under existing nodejs folder so that minimal diff would appear ?

@davidchase
Copy link
Contributor Author

@sanketsudake ive moved the files into nodejs directory and removed nodejs22 directory and updated tests and added esm examples

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds Node.js 22 runtime environment support with ESM (ECMAScript modules) capabilities to the existing Node.js environment, while maintaining backward compatibility with the original CommonJS-based Node.js runtime.

  • Converts the existing Node.js runtime to support both ESM and CJS module loading modes
  • Updates dependencies to modern versions (Express 5.1.0, Pino logging, WebSocket 8.18.3)
  • Adds comprehensive test coverage for both ESM and CJS function formats

Reviewed Changes

Copilot reviewed 24 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
nodejs/server.js Core runtime conversion to ESM with dual CJS/ESM module loading support
nodejs/package.json Package configuration updated for ESM with modern dependencies
nodejs/test/test_node_env.sh Enhanced test script supporting both CJS and ESM function testing
nodejs/test/local_test.sh Comprehensive local testing framework for multiple function types
nodejs/test/test-case-*/*.js New ESM test cases and updated CJS test cases with proper module configuration
nodejs/examples/*.js ESM example functions demonstrating Node.js 22 features
Makefile Added nodejs22 test image targets
.github/workflows/environment.yaml Duplicate fission dump collection step
Files not reviewed (3)
  • nodejs/package-lock.json: Language not supported
  • nodejs/test/test-case-4/package-lock.json: Language not supported
  • nodejs/test/test-case-8/package-lock.json: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@davidchase
Copy link
Contributor Author

is there a way to auto run the actions for this PR? that way we can have a tighter feedback loop?

@sanketsudake sanketsudake self-requested a review August 19, 2025 13:19
The body variable needs escaped double quotes to properly pass
the full string 'Its a beautiful day' through bash -c invocation
@sanketsudake
Copy link
Member

Please update the version here to 1.33 for the new release
https://github.com/fission/environments/blob/master/nodejs/envconfig.json

@sanketsudake sanketsudake merged commit e3bb394 into fission:master Aug 20, 2025
12 checks passed
@sanketsudake
Copy link
Member

Thanks @davidchase, for all your hard work on the PR and for considering my suggestions. 🎉

@davidchase davidchase deleted the recover-pr-nodejs22 branch August 20, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ES module support for Node JS

3 participants