Skip to content

Instantly share code, notes, and snippets.

@shazron
Last active August 28, 2023 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shazron/c05b451314d6dedf46c6fd955a33b2f6 to your computer and use it in GitHub Desktop.
Save shazron/c05b451314d6dedf46c6fd955a33b2f6 to your computer and use it in GitHub Desktop.
OpenWhisk - how to use an EcmaScript Module (ESM) in node.js
// ///////////////////////////////////////////////////////////////////
// index.cjs - this is exported in the manifest for Openwhisk Deploy
// Only supported in Node 14+ (dynamic import)
async function cjsMain(params) {
const { default: esmMain } = await import('./index.mjs')
return esmMain(params)
}
exports.main = cjsMain
// //////////////////////////////////////////////////////////////////////////
// index.mjs - this is the EcmaScript Module that contains the functionality
export default function (params) {
return {
statusCode: 200,
headers: {
'Content-Type': 'application/json'
},
body: {
LOG_LEVEL: params.LOG_LEVEL,
message: 'this is a test message'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment