Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Last active May 8, 2022 09:32
Show Gist options
  • Save xgqfrms/1981c08fcb7e09056e1c5d9192f272c8 to your computer and use it in GitHub Desktop.
Save xgqfrms/1981c08fcb7e09056e1c5d9192f272c8 to your computer and use it in GitHub Desktop.
math.js module just for npx execute gist js module testing!
#!/usr/bin/env node
// math.js & `bin` package.json
console.log('math.js 👻');
const add = (a, b) => {
return a + b;
}
const math = {
add,
};
// test case
const result = add(1, 2);
console.log('result =', result, result === (1 + 2) ? '✅' : '❌');
// ESM
// export default math;
// Declaration or statement expected.ts(1128) ❌
// export math;
// CJS
// module.exports.add = add;
module.exports = math;
{
"version": "0.0.4",
"name": "math.js",
"author": "xgqfrms",
"main": "./math.js",
"bin": "./math.js"
}
@xgqfrms
Copy link
Author

xgqfrms commented May 8, 2022

how to use gist as an npm module ✅

steps

  1. create one gist, readme.md or whatever filename

  2. edit gist

  3. add file

image

https://www.cnblogs.com/xgqfrms/p/16246009.html

@xgqfrms
Copy link
Author

xgqfrms commented May 8, 2022

solution

$ npx https://gist.github.com/xgqfrms/1981c08fcb7e09056e1c5d9192f272c8


$ npx gist:1981c08fcb7e09056e1c5d9192f272c8

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment