Introduction to MJS
This document provides an introduction to MJS (.mjs) also known as Modular JavaScript
CommonJS (NodeJS) example
// To include the File System module, use the require() method
const fs = require('fs');
// Using the File System module to read files
fs.readFile();
// Exporting the greet function so it can be used in other modules, use module.exports
module.exports = function greet(name) {
return 'Hello, ${name}!';
};// To include the File System module, you no longer use require() method
// Use import instead.
import fs from 'fs';
// Using the File System module to read files
fs.readFile();
// Exporting the greet function so it can be used in other modules, you no longer
// use `module.exports`. Use `export` instead.
export const greet = (name) => {
return 'Hello, ${name}!';
};MJS PlayCanvas Script Structure
Accessing a function in a MJS(.mjs) file from regular JavaScript (.js) code example
Debugging MJS files




MJS file with custom properties and methods example
Key Examples
Last updated
Was this helpful?




