{"id":13648745,"url":"https://github.com/wasmerio/wasmer-js","last_synced_at":"2025-05-13T23:10:18.363Z","repository":{"id":40267479,"uuid":"192390837","full_name":"wasmerio/wasmer-js","owner":"wasmerio","description":"Monorepo for Javascript WebAssembly packages by Wasmer","archived":false,"fork":false,"pushed_at":"2025-04-28T09:39:45.000Z","size":48758,"stargazers_count":998,"open_issues_count":44,"forks_count":88,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-05-10T13:40:32.975Z","etag":null,"topics":["nodejs","npm-package","wasi","wasix","webassembly"],"latest_commit_sha":null,"homepage":"https://wasmerio.github.io/wasmer-js/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wasmerio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-17T17:32:00.000Z","updated_at":"2025-05-08T14:08:00.000Z","dependencies_parsed_at":"2023-10-24T09:24:48.213Z","dependency_job_id":"c1665aaa-8dd9-4fad-afc5-96a129337680","html_url":"https://github.com/wasmerio/wasmer-js","commit_stats":{"total_commits":425,"total_committers":14,"mean_commits":"30.357142857142858","dds":0.4423529411764706,"last_synced_commit":"845dfd194a6f87d70c29327ce363e9e46c083408"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wasmerio%2Fwasmer-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wasmerio","download_url":"https://codeload.github.com/wasmerio/wasmer-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253592890,"owners_count":21932900,"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","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":["nodejs","npm-package","wasi","wasix","webassembly"],"created_at":"2024-08-02T01:04:30.220Z","updated_at":"2025-05-13T23:10:13.331Z","avatar_url":"https://github.com/wasmerio.png","language":"Rust","funding_links":[],"categories":["Rust","webassembly","Projects","JavaScript"],"sub_categories":["Libraries"],"readme":"# The Wasmer JavaScript SDK\n\n[![npm (scoped)](https://img.shields.io/npm/v/%40wasmer/sdk)](https://npmjs.org/package/@wasmer/sdk)\n[![NPM Downloads](https://img.shields.io/npm/dm/%40wasmer%2Fsdk)](https://npmjs.org/package/@wasmer/sdk)\n[![License](https://img.shields.io/npm/l/%40wasmer%2Fsdk)](./LICENSE)\n[![Wasmer Discord Channel](https://img.shields.io/discord/1110300506942881873)](https://discord.gg/qBTfsNP7N8)\n[![API Docs](https://img.shields.io/badge/API%20Docs-open-blue?link=wasmerio.github.io%2Fwasmer-js%2F)](https://wasmerio.github.io/wasmer-js/)\n\nJavascript library for running Wasmer packages at ease, including WASI and WASIX modules.\n\n## Getting Started\n\n### Install from NPM\n\nFor instaling `@wasmer/sdk`, run this command in your shell:\n\n```bash\nnpm install --save @wasmer/sdk\n```\n\nYou can now run packages from the Wasmer registry:\n\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\n\nawait init();\n\nconst pkg = await Wasmer.fromRegistry(\"python/python\");\nconst instance = await pkg.entrypoint.run({\n    args: [\"-c\", \"print('Hello, World!')\"],\n});\n\nconst { code, stdout } = await instance.wait();\nconsole.log(`Python exited with ${code}: ${stdout}`);\n```\n### Use with a `\u003cscript\u003e` tag (without bundler)\n\nIt is possible to avoid needing to use a bundler by importing `@wasmer/sdk` from your script tag in unpkg.\n\n```html\n\u003cscript defer type=\"module\"\u003e\n    import { init, Wasmer } from \"https://unpkg.com/@wasmer/sdk@latest/dist/index.mjs\";\n\n    async function runPython() {\n        await init();\n\n        const packageName = \"python/python\";\n        const pkg = await Wasmer.fromRegistry(packageName);\n        const instance = await pkg.entrypoint.run({\n            args: [\"-c\", \"print('Hello, World!')\"],\n        });\n\n        const { code, stdout } = await instance.wait();\n\n        console.log(`Python exited with ${code}: ${stdout}`);\n    }\n\n    runPython();\n\u003c/script\u003e\n```\n\n\n### Using a custom Wasm file\n\nBy default, `init` will load the Wasmer SDK WebAssembly file from the package.\nIf you want to customize this behavior you can pass a custom url to the init, so the the wasm file\nof the Wasmer SDK can ve served by your HTTP server instead:\n\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\nimport wasmerSDKModule from \"@wasmer/sdk/wasm?url\";\n\nawait init({ module: wasmUrl }); // This inits the SDK with a custom URL\n```\n\n\n### Using a JS with the Wasm bundled\n\nYou can also load Wasmer-JS with a js file with the Wasmer SDK WebAssembly file bundled into it (using base64 encoding),\nso no extra requests are required. If that's your use case, you can simply import `@wasmer/sdk/wasm-inline`:\n\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\nimport wasmerSDKModule from \"@wasmer/sdk/wasm-inline\";\n\nawait init({ module: wasmerSDKModule }); // This uses the inline wasmer SDK version\n```\n\n\n### Cross-Origin Isolation\n\nBrowsers have implemented security measures to mitigate the Spectre and Meltdown\nvulnerabilities.\n\nThese measures restrict the sharing of `SharedArrayBuffer`` objects with Web\nWorkers unless the execution context is deemed secure.\n\nThe `@wasmer/sdk` package uses a threadpool built on Web Workers and requires\nsharing the same `SharedArrayBuffer` across multiple workers to enable WASIX\nthreads to access the same address space. This requirement is crucial even for\nrunning single-threaded WASIX programs because the SDK internals rely on\n`SharedArrayBuffer` for communication with Web Workers.\n\nTo avoid Cross-Origin Isolation issues, make sure any web pages using\n`@wasmer/sdk` are served over HTTPS and have the following headers set:\n\n```yaml\n\"Cross-Origin-Opener-Policy\": \"same-origin\"\n\"Cross-Origin-Embedder-Policy\": \"require-corp\"\n```\n\nSee the [`SharedArrayBuffer` and Cross-Origin Isolation][coi-docs] section under\nthe *Troubleshooting Common Problems* docs for more.\n\n### Creating packages \n\nUsers can create packages providing a manifest and using the `Wasmer.createPackage()` function: \n\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\n\nawait init({ token: \"YOUR_TOKEN\" });\n\nconst manifest = {\n    command: [\n        {\n            module: \"wasmer/python:python\",\n            name: \"hello\",\n            runner: \"wasi\",\n            annotations: {\n                wasi: {\n                    \"main-args\": [\n                        \"-c\",\n                        \"print('Hello, js!'); \",\n                    ],\n                },\n            },\n        },\n    ],\n    dependencies: {\n        \"wasmer/python\": \"3.12.9+build.9\",\n    }\n};\n\nlet pkg = await Wasmer.createPackage(manifest);\nlet instance = await pkg.commands[\"hello\"].run();\n\nconst output = await instance.wait();\nconsole.log(output)\n```\n\n### Publishing packages\n\nUser can publish packages following the same flow used to create a package and then calling the `Wasmer.publishPackage()` function:\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\n\nawait init({ token: \"YOUR_TOKEN\" });\n\nconst manifest = {\n    package: {\n        name: \"\u003cYOUR_NAME\u003e/\u003cYOUR_PACKAGE_NAME\u003e\"\n    }\n    command: [\n        {\n            module: \"wasmer/python:python\",\n            name: \"hello\",\n            runner: \"wasi\",\n            annotations: {\n                wasi: {\n                    \"main-args\": [\n                        \"-c\",\n                        \"print('Hello, js!'); \",\n                    ],\n                },\n            },\n        },\n    ],\n    dependencies: {\n        \"wasmer/python\": \"3.12.9+build.9\",\n    }\n};\n\nlet pkg = await Wasmer.createPackage(manifest);\nawait Wasmer.publishPackage(pkg);\n```\nTrying to publish packages without a `package.name` property in the manifest will result in a failure. \n\n### Deploying apps  \nUser can deploy apps by providing an app configuration and calling the `Wasmer.deployApp()` function:\n```js\nimport { init, Wasmer } from \"@wasmer/sdk\";\n\n// Get your token here: https://wasmer.io/settings/access-tokens\nawait init({ token: \"YOUR_TOKEN\" });\n\nlet appConfig = {\n  name: \"\u003cYOUR_APP_NAME\u003e\",\n  owner: \"\u003cYOUR_NAME\u003e\",\n  package: \"wasmer/hello\"\n  default: true,\n};\n\nawait Wasmer.deployApp(appConfig);\n```\n\nUsers can also publish apps with their own packages simply providing the package in the config: \n\n```js\nimport wasmUrl from \"@wasmer/sdk\";\n\n// Get your token here: https://wasmer.io/settings/access-tokens\nawait init({token: \"YOUR_TOKEN\"});\n\nconst echo_server_index = `\n    async function handler(request) {\n      const out = JSON.stringify({\n        env: process.env,\n      });\n      return new Response(out, {\n        headers: { \"content-type\": \"application/json\" },\n      });\n    }\n    \n    addEventListener(\"fetch\", (fetchEvent) =\u003e {\n      fetchEvent.respondWith(handler(fetchEvent.request));\n    });\n    `;\n\n\nconst manifest =\n{\n    \"command\": [\n        {\n            \"module\": \"wasmer/winterjs:winterjs\",\n            \"name\": \"script\",\n            \"runner\": \"https://webc.org/runner/wasi\",\n            \"annotations\": {\n                \"wasi\": {\n                    \"env\": [\n                        \"JS_PATH=/src/index.js\"\n                    ],\n                    \"main-args\": [\n                        \"/src/index.js\"\n                    ]\n                }\n            }\n        }\n    ],\n    \"dependencies\": {\n        \"wasmer/winterjs\": \"1.2.0\"\n    },\n    \"fs\": {\n        \"/src\": {\n            \"index.js\": echo_server_index\n        }\n    },\n};\n\nlet wasmerPackage = await Wasmer.createPackage(manifest);\n\nlet appConfig = {\n    name: \"my-echo-env-app\",\n    owner: \"edoardo\",\n    package: wasmerPackage,\n    default: true,\n};\n\nlet res = await Wasmer.deployApp(appConfig);\nconsole.log(res.url)\n```\n# Features\n\nThe Wasmer SDK Javascript Package supports:\n\n* [X] WASI support\n  * [X] Environment variables\n  * [X] FileSystem access\n  * [X] Command-line arguments\n  * [X] Stdio\n* [X] WASIX support\n  * [X] Multi-threading\n  * [X] Spawning sub-processes\n  * [ ] Networking (on the works)\n* [X] Mounting directories inside the WASIX instance\n* [X] Running packages from the [Wasmer Registry](https://wasmer.io)\n* [X] Platforms\n  * [X] Browser\n  * [x] NodeJS\n  * [ ] Deno\n* [X] Registry API\n  * [X] Create a package\n  * [X] Publish a package\n  * [X] Deploy an application \n\n# License\n\nThe entire project is under the MIT License. Please read [the\n`LICENSE` file][license].\n\n[coi-docs]: https://docs.wasmer.io/javascript-sdk/explainers/troubleshooting#sharedarraybuffer-and-cross-origin-isolation\n[license]: https://github.com/wasmerio/wasmer/blob/master/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwasmerio%2Fwasmer-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwasmerio%2Fwasmer-js/lists"}