Javascript Training 2026

From bibbleWiki
Revision as of 21:21, 24 May 2026 by Iwiseman (talk | contribs) (Node)
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

{
  "name" : "myModule",
  "main" : "./stimpy.js"
}

You put your file stimpy.js in the same directory

module.exports = {
  speak: function() {
    return "happy, happy, joy, joy";
  }
};

So in your main you can import the folder

const fun = require('./fun_m');

console.log(fun.speak());