Skip to content

Commit e3bb394

Browse files
authored
feat: add nodejs 22 env (#424)
* feat: add nodejs 22 env * feat: update README * fix: resolve comments * fix: add nodejs22 to environment.yaml * fix: nodejs env tests * feat: support ESM and CJS with LOAD_ENV env var * fix: remove local specific images * fix: move from nodejs22 into nodejs and remove nodejs22 dir * fix: remove nodejs22 dir * fix: make updates requested * fix: swap to requires for server.js * fix: add newline * fix: add missing type module for test-case-5 * fix: update tests again * fix: broken test cases * fix: properly quote body parameter in test_post_route call The body variable needs escaped double quotes to properly pass the full string 'Its a beautiful day' through bash -c invocation * fix: bump version * fix: remove extra space * fix: rename package.json
1 parent 863298b commit e3bb394

24 files changed

+1517
-926
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ environments-ui/node_modules
33
environments-ui/public/bundle.js
44
environments-ui/server.js
55
.vscode
6+
node_modules
7+
**/node_modules/**
8+
*.DS_Store

nodejs/envconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"runtimeVersion": "20.16.0-debian",
2121
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
2222
"status": "Stable",
23-
"version": "1.32.5"
23+
"version": "1.33"
2424
},
2525
{
2626
"builder": "node-builder-22",
@@ -44,7 +44,7 @@
4444
"runtimeVersion": "22.6.0",
4545
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
4646
"status": "Stable",
47-
"version": "1.32.5"
47+
"version": "1.33"
4848
},
4949
{
5050
"builder": "node-builder",
@@ -68,6 +68,6 @@
6868
"runtimeVersion": "20.16.0",
6969
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
7070
"status": "Stable",
71-
"version": "1.32.5"
71+
"version": "1.33"
7272
}
7373
]

nodejs/examples/hello-esm.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default async (context) => {
2+
return {
3+
status: 200,
4+
body: JSON.stringify({
5+
message: "Hello from Node.js 22 Pure ESM! 🚀",
6+
nodeVersion: process.version,
7+
moduleType: "ESM",
8+
timestamp: new Date().toISOString()
9+
}, null, 2),
10+
headers: {
11+
"Content-Type": "application/json"
12+
}
13+
};
14+
};

nodejs/examples/multi-entry-esm.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
export const entry1 = async (context) => {
2+
const { request } = context;
3+
const name = request.query?.name || 'World';
4+
5+
return {
6+
status: 200,
7+
body: JSON.stringify({
8+
message: `Hello from Entry Point 1, ${name}! 🚀`,
9+
entryPoint: 'entry1',
10+
nodeVersion: process.version,
11+
timestamp: new Date().toISOString(),
12+
features: ['Named Exports', 'ESM Modules', 'Multiple Endpoints']
13+
}, null, 2),
14+
headers: {
15+
'Content-Type': 'application/json',
16+
'X-Entry-Point': 'entry1'
17+
}
18+
};
19+
};
20+
21+
export const entry2 = async (context) => {
22+
const { request } = context;
23+
const data = request.body || {};
24+
25+
return {
26+
status: 200,
27+
body: JSON.stringify({
28+
message: `Greetings from Entry Point 2! 🎯`,
29+
entryPoint: 'entry2',
30+
nodeVersion: process.version,
31+
timestamp: new Date().toISOString(),
32+
receivedData: data,
33+
capabilities: ['Data Processing', 'JSON Handling', 'Modern ESM']
34+
}, null, 2),
35+
headers: {
36+
'Content-Type': 'application/json',
37+
'X-Entry-Point': 'entry2'
38+
}
39+
};
40+
};

nodejs/examples/weather-esm.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Weather API example for Node.js 22 ESM
2+
// Uses Node.js 22's built-in fetch API (no external dependencies needed!)
3+
4+
export default async (context) => {
5+
const { request } = context;
6+
// Support both body and query parameters
7+
const location = request.body?.location || request.query?.location;
8+
9+
if (!location) {
10+
return {
11+
status: 400,
12+
body: JSON.stringify({
13+
error: 'Location is required',
14+
usage: {
15+
post: 'POST with {"location": "City, Country"}',
16+
get: 'GET with ?location=City,Country',
17+
example: '{"location": "San Francisco, CA"}'
18+
}
19+
}),
20+
headers: {
21+
'Content-Type': 'application/json'
22+
}
23+
};
24+
}
25+
26+
try {
27+
// Note: This example uses mock weather data
28+
// In production, replace with a real weather API like OpenWeatherMap
29+
const mockWeatherData = {
30+
location,
31+
temperature: Math.floor(Math.random() * 30) + 5, // 5-35°C
32+
condition: ['Sunny', 'Cloudy', 'Rainy', 'Partly Cloudy', 'Thunderstorms'][Math.floor(Math.random() * 5)],
33+
humidity: Math.floor(Math.random() * 40) + 30, // 30-70%
34+
windSpeed: Math.floor(Math.random() * 20) + 5, // 5-25 km/h
35+
uvIndex: Math.floor(Math.random() * 11), // 0-10
36+
visibility: Math.floor(Math.random() * 15) + 5, // 5-20 km
37+
timestamp: new Date().toISOString(),
38+
coordinates: {
39+
lat: (Math.random() * 180 - 90).toFixed(4),
40+
lon: (Math.random() * 360 - 180).toFixed(4)
41+
}
42+
};
43+
44+
// Simulate weather severity
45+
const severity = mockWeatherData.condition === 'Thunderstorms' ? 'high' :
46+
mockWeatherData.condition === 'Rainy' ? 'medium' : 'low';
47+
48+
return {
49+
status: 200,
50+
body: JSON.stringify({
51+
success: true,
52+
data: {
53+
...mockWeatherData,
54+
severity,
55+
recommendation: severity === 'high' ? 'Stay indoors' :
56+
severity === 'medium' ? 'Bring an umbrella' : 'Great weather for outdoor activities'
57+
},
58+
message: `Current weather in ${location}: ${mockWeatherData.temperature}°C and ${mockWeatherData.condition}`,
59+
nodeVersion: process.version,
60+
builtInFetch: 'Node.js 22 native fetch API ready for real weather services!',
61+
requestMethod: request.method || 'GET'
62+
}, null, 2),
63+
headers: {
64+
'Content-Type': 'application/json',
65+
'X-Weather-Source': 'mock-data',
66+
'X-Node-Version': process.version
67+
}
68+
};
69+
} catch (error) {
70+
return {
71+
status: 500,
72+
body: JSON.stringify({
73+
error: 'Failed to fetch weather data',
74+
details: error.message,
75+
nodeVersion: process.version
76+
}),
77+
headers: {
78+
'Content-Type': 'application/json'
79+
}
80+
};
81+
}
82+
};

0 commit comments

Comments
 (0)