Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ environments-ui/node_modules
environments-ui/public/bundle.js
environments-ui/server.js
.vscode
node_modules
**/node_modules/**
*.DS_Store
6 changes: 3 additions & 3 deletions nodejs/envconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"runtimeVersion": "20.16.0-debian",
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
"status": "Stable",
"version": "1.32.5"
"version": "1.33"
},
{
"builder": "node-builder-22",
Expand All @@ -44,7 +44,7 @@
"runtimeVersion": "22.6.0",
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
"status": "Stable",
"version": "1.32.5"
"version": "1.33"
},
{
"builder": "node-builder",
Expand All @@ -68,6 +68,6 @@
"runtimeVersion": "20.16.0",
"shortDescription": "Fission NodeJS environment based on Express with some basic dependencies added",
"status": "Stable",
"version": "1.32.5"
"version": "1.33"
}
]
14 changes: 14 additions & 0 deletions nodejs/examples/hello-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export default async (context) => {
return {
status: 200,
body: JSON.stringify({
message: "Hello from Node.js 22 Pure ESM! 🚀",
nodeVersion: process.version,
moduleType: "ESM",
timestamp: new Date().toISOString()
}, null, 2),
headers: {
"Content-Type": "application/json"
}
};
};
40 changes: 40 additions & 0 deletions nodejs/examples/multi-entry-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
export const entry1 = async (context) => {
const { request } = context;
const name = request.query?.name || 'World';

return {
status: 200,
body: JSON.stringify({
message: `Hello from Entry Point 1, ${name}! 🚀`,
entryPoint: 'entry1',
nodeVersion: process.version,
timestamp: new Date().toISOString(),
features: ['Named Exports', 'ESM Modules', 'Multiple Endpoints']
}, null, 2),
headers: {
'Content-Type': 'application/json',
'X-Entry-Point': 'entry1'
}
};
};

export const entry2 = async (context) => {
const { request } = context;
const data = request.body || {};

return {
status: 200,
body: JSON.stringify({
message: `Greetings from Entry Point 2! 🎯`,
entryPoint: 'entry2',
nodeVersion: process.version,
timestamp: new Date().toISOString(),
receivedData: data,
capabilities: ['Data Processing', 'JSON Handling', 'Modern ESM']
}, null, 2),
headers: {
'Content-Type': 'application/json',
'X-Entry-Point': 'entry2'
}
};
};
82 changes: 82 additions & 0 deletions nodejs/examples/weather-esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Weather API example for Node.js 22 ESM
// Uses Node.js 22's built-in fetch API (no external dependencies needed!)

export default async (context) => {
const { request } = context;
// Support both body and query parameters
const location = request.body?.location || request.query?.location;

if (!location) {
return {
status: 400,
body: JSON.stringify({
error: 'Location is required',
usage: {
post: 'POST with {"location": "City, Country"}',
get: 'GET with ?location=City,Country',
example: '{"location": "San Francisco, CA"}'
}
}),
headers: {
'Content-Type': 'application/json'
}
};
}

try {
// Note: This example uses mock weather data
// In production, replace with a real weather API like OpenWeatherMap
const mockWeatherData = {
location,
temperature: Math.floor(Math.random() * 30) + 5, // 5-35°C
condition: ['Sunny', 'Cloudy', 'Rainy', 'Partly Cloudy', 'Thunderstorms'][Math.floor(Math.random() * 5)],
humidity: Math.floor(Math.random() * 40) + 30, // 30-70%
windSpeed: Math.floor(Math.random() * 20) + 5, // 5-25 km/h
uvIndex: Math.floor(Math.random() * 11), // 0-10
visibility: Math.floor(Math.random() * 15) + 5, // 5-20 km
timestamp: new Date().toISOString(),
coordinates: {
lat: (Math.random() * 180 - 90).toFixed(4),
lon: (Math.random() * 360 - 180).toFixed(4)
}
};

// Simulate weather severity
const severity = mockWeatherData.condition === 'Thunderstorms' ? 'high' :
mockWeatherData.condition === 'Rainy' ? 'medium' : 'low';

return {
status: 200,
body: JSON.stringify({
success: true,
data: {
...mockWeatherData,
severity,
recommendation: severity === 'high' ? 'Stay indoors' :
severity === 'medium' ? 'Bring an umbrella' : 'Great weather for outdoor activities'
},
message: `Current weather in ${location}: ${mockWeatherData.temperature}°C and ${mockWeatherData.condition}`,
nodeVersion: process.version,
builtInFetch: 'Node.js 22 native fetch API ready for real weather services!',
requestMethod: request.method || 'GET'
}, null, 2),
headers: {
'Content-Type': 'application/json',
'X-Weather-Source': 'mock-data',
'X-Node-Version': process.version
}
};
} catch (error) {
return {
status: 500,
body: JSON.stringify({
error: 'Failed to fetch weather data',
details: error.message,
nodeVersion: process.version
}),
headers: {
'Content-Type': 'application/json'
}
};
}
};
Loading