Javascript Training 2026
Introduction
Never thought I would be doing this. Love typescript and this will be a challenge but doing more with less is fun too. So on here will be the bits I never knew about JS
Node
commonJS module.exports = require. And although import works for a function, it does not work for a class so you have to use it
ESM export = import
So never made a package outside of using npm so this was a surprise. Make a folder fun_m and add package.json
<syntaxhighlight lang="json">
{
"name" : "myModule", "main" : "./stimpy.js"
} <syntaxhighlight> You put your file stimpy.js in the same directory <syntaxhighlight lang="js"> module.exports = {
speak: function() {
return "happy, happy, joy, joy";
}
}; <syntaxhighlight> So in your main you can import the folder <syntaxhighlight lang="js"> const fun = require('./fun_m');
console.log(fun.speak()); <syntaxhighlight>