{"id":30703153,"url":"https://github.com/dfinity/node-motoko","last_synced_at":"2025-10-05T23:16:24.829Z","repository":{"id":49822064,"uuid":"518261612","full_name":"dfinity/node-motoko","owner":"dfinity","description":"Compile and run Motoko smart contracts in Node.js or the browser.","archived":false,"fork":false,"pushed_at":"2025-09-30T12:47:08.000Z","size":50675,"stargazers_count":19,"open_issues_count":6,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-09-30T14:37:39.603Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dfinity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-07-27T00:53:10.000Z","updated_at":"2025-09-30T12:21:29.000Z","dependencies_parsed_at":"2022-08-12T20:40:53.909Z","dependency_job_id":"94563680-90ab-4c0c-b3d3-1bf8ca3ac965","html_url":"https://github.com/dfinity/node-motoko","commit_stats":{"total_commits":191,"total_committers":2,"mean_commits":95.5,"dds":0.005235602094240788,"last_synced_commit":"d75c859bbb3b4da3bc74df3a4b5ce5e154e035cc"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dfinity/node-motoko","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinity%2Fnode-motoko","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinity%2Fnode-motoko/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinity%2Fnode-motoko/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinity%2Fnode-motoko/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dfinity","download_url":"https://codeload.github.com/dfinity/node-motoko/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dfinity%2Fnode-motoko/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278532352,"owners_count":26002346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-02T16:56:25.888Z","updated_at":"2025-10-05T23:16:24.801Z","avatar_url":"https://github.com/dfinity.png","language":"TypeScript","readme":"\n# `motoko` \u0026nbsp;[![npm version](https://img.shields.io/npm/v/motoko.svg?logo=npm)](https://www.npmjs.com/package/motoko) [![GitHub license](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/dfinity/motoko/issues)\n\n\u003e #### Compile and run [Motoko](https://smartcontracts.org/) smart contracts in Node.js or the browser.\n\n---\n\n## Installation:\n\n```sh\nnpm i --save motoko\n```\n\n## Examples:\n\n### Basic usage\n\n```js\nimport mo from 'motoko';\n// -- OR --\nconst mo = require('motoko');\n\n// Create a Motoko script in a virtual file system\nmo.write('Main.mo', `\n  actor {\n      public query func hello() : async Text {\n          \"Hello, JavaScript!\"\n      };\n  }\n`);\n\n// Generate the corresponding Candid interface\nconsole.log(mo.candid('Main.mo'));\n```\n\n### Evaluate a program\n\n```js\nmo.write('Main.mo', `\n  actor Main {\n    public query func hello() : async Text {\n      \"Hello, world!\"\n    };\n  };\n  await Main.hello();\n`)\nmo.run('Main.mo');\n```\n\n### Evaluate a program (shorthand)\n\n```js\nmo.file('Main.mo')\n    .write('actor Main { public query func getNumber() : async Nat { 5 } }')\n    .run();\n```\n\n### Load dependencies from GitHub\n\n```js\nmo.clearPackages();\nawait mo.installPackages({\n    base: 'dfinity/motoko-core/main/src', // import \"mo:core/...\";\n});\n```\n\n### Generate parse trees\n\n```js\n// Generate a Motoko AST\nconsole.log(mo.parseMotoko('actor Main { public query func test() : async Nat { 123 } }'));\n\n// Generate a Candid AST\nconsole.log(mo.parseCandid('service : { test : () -\u003e (nat) }'));\n```\n\n### Optimize for browsers\n\n```js\n// Load just the `write()`, `loadPackages()`, `clearPackages()`, and `run()`, operations for a smaller file size:\nimport mo from 'motoko/interpreter';\n```\n\n## API:\n\n### Top-level API\n\n```js\n// Read the contents of a virtual file\nmo.read(path)\n\n// Write a string to a virtual file\nmo.write(path, string)\n\n// Rename a virtual file\nmo.rename(path, newPath)\n\n// Delete a virtual file\nmo.delete(path)\n\n// List the files in a virtual directory\nmo.list(path)\n\n// Fetch a package from GitHub or jsDelivr\nawait mo.fetchPackage(name, source);\nawait mo.fetchPackage('base', 'dfinity/motoko-base/master/src');\n\n// Try to fetch and load packages from GitHub or jsDelivr\nawait mo.installPackages({ [packageName]: repositoryPath, ... })\n\n// Load a value returned from `fetchPackage()`\nmo.loadPackage(package)\n\n// Use a virtual directory as a package\nmo.usePackage(packageName, directory)\n\n// Clear loaded packages\nmo.clearPackages()\n\n// Ensure that a package is correctly formatted\nmo.validatePackage(package)\n\n// Configure the compiler to resolve `import \"mo:{alias}\";` -\u003e `import \"canister:{id}\";`\n// `directory` should contain `*.did` files for canister dependencies\nmo.setAliases(directory, { alias: id, ... })\n\n// Set the public metadata (an array of strings) used by the compiler\nmo.setPublicMetadata(strings)\n\n// Set the maximum number of interpreter steps before cancelling a `run()` invocation\nmo.setRunStepLimit(limit)\n\n// Generate errors and warnings for a Motoko program\nmo.check(path)\n\n// Run a Motoko program with optional virtual library paths\nmo.run(path)\nmo.run(path, [libraryPath, ...])\n\n// Generate the Candid interface for a Motoko program\nmo.candid(path)\n\n// Compile a Motoko program to WebAssembly\nmo.wasm(path, 'ic') // IC interface format (default)\nmo.wasm(path, 'wasi') // WASI interface format\n\n// Return the parse tree for a Candid string\nmo.parseCandid(candidString)\n\n// Return the parse tree for a Motoko string\nmo.parseMotoko(motokoString)\n\n// Return the typed parse tree for a Motoko file path (or array of paths)\nmo.parseMotokoTyped(path)\nmo.parseMotokoTyped(paths = [...])\n\n// Find the 'Main.mo' file or an equivalent canister entry point\nmo.resolveMain(directory = '')\n\n// Find the 'Lib.mo' file or an equivalent library entry point\nmo.resolveLib(directory = '')\n\n// Get the compiler version ('latest' by default)\nmo.version\n\n// Access the underlying Motoko compiler\nmo.compiler\n```\n\n### File API\n\n```js\n// Create an object representing a virtual file\nconst file = mo.file('Main.mo')\n\n// Get the file path\nfile.path\n\n// Get another file object with the same path\nfile.clone()\n\n// Read the file as a string\nfile.read()\n\n// Write a string to the file\nfile.write(string)\n\n// Rename the file\nfile.rename(newPath)\n\n// Delete the file\nfile.delete()\n\n// List children (if a directory)\nfile.list()\n\n// Generate errors and warnings for a Motoko program\nfile.check()\n\n// Run the file as a Motoko program\nfile.run()\n\n// Generate the Candid interface for a Motoko program\nfile.candid()\n\n// Compile the file to WebAssembly (see `mo.wasm()`)\nfile.wasm('ic')\nfile.wasm('wasi') // note: cannot contain actors\n\n// Parse the file as a Motoko program\nfile.parseMotoko()\n\n// Parse the file as a Candid interface\nfile.parseCandid()\n\n// Parse the file (with types) as a Motoko program\nfile.parseMotokoTyped()\n```\n\n## Contributing\n\nPRs are welcome! Please check out the [contributor guidelines](https://github.com/dfinity/node-motoko/blob/main/.github/CONTRIBUTING.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinity%2Fnode-motoko","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdfinity%2Fnode-motoko","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdfinity%2Fnode-motoko/lists"}