Javascript Training 2026

From bibbleWiki
Revision as of 21:20, 24 May 2026 by Iwiseman (talk | contribs) (Created page with "=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<br> ESM '''export''' = '''import'''<br> <br> So never made a package outside of using npm so this was a surprise. Make a folder fun_m and add p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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>