{"id":13527375,"url":"https://github.com/bytenode/bytenode","last_synced_at":"2025-05-13T00:14:17.611Z","repository":{"id":38475193,"uuid":"154481603","full_name":"bytenode/bytenode","owner":"bytenode","description":"A minimalist bytecode compiler for Node.js","archived":false,"fork":false,"pushed_at":"2025-02-08T22:25:35.000Z","size":968,"stargazers_count":2770,"open_issues_count":20,"forks_count":183,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-05-13T00:14:13.127Z","etag":null,"topics":["bytecode","bytenode","compiler","nodejs","source-code-protection","v8"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/bytenode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":"2018-10-24T10:23:29.000Z","updated_at":"2025-05-11T22:36:10.000Z","dependencies_parsed_at":"2022-08-09T04:18:44.959Z","dependency_job_id":"be4dc6ec-f72b-4284-948a-bd63f1efb8ba","html_url":"https://github.com/bytenode/bytenode","commit_stats":{"total_commits":150,"total_committers":9,"mean_commits":"16.666666666666668","dds":0.3466666666666667,"last_synced_commit":"e34af4de9e544fd0beb9fb4fbfdf16db1a6937b5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytenode%2Fbytenode","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytenode%2Fbytenode/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytenode%2Fbytenode/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bytenode%2Fbytenode/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bytenode","download_url":"https://codeload.github.com/bytenode/bytenode/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843225,"owners_count":21972874,"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":["bytecode","bytenode","compiler","nodejs","source-code-protection","v8"],"created_at":"2024-08-01T06:01:46.674Z","updated_at":"2025-05-13T00:14:17.589Z","avatar_url":"https://github.com/bytenode.png","language":"JavaScript","readme":"# Bytenode\n\nA minimalist bytecode compiler for Node.js.\n\nThis tool truly compiles your JavaScript code into `V8` bytecode, so that you can protect your source code. It can be used with Node.js, as well as Electron and NW.js (check `examples/` directory).\n\n---\n\n## Install\n\n```console\nnpm install --save bytenode\n```\n\nOr globally:\n\n```console\nsudo npm install -g bytenode\n```\n\n---\n\n## Known Issues and Limitations\n\n* In Node 10.x, Bytenode does not work in debug mode. See [#29](https://github.com/bytenode/bytenode/issues/29).\n\n* Any code depends on `Function.prototype.toString` function will break, because Bytenode removes the source code from `.jsc` files and puts a dummy code instead. See [#34](https://github.com/bytenode/bytenode/issues/34). For a workaround, see [#163](https://github.com/bytenode/bytenode/issues/163)\n\n* Async Arrow Functions (and Arrow Functions in general) cause crashes in Puppeteer and in Electron apps. See [#106](https://github.com/bytenode/bytenode/issues/106), [#47](https://github.com/bytenode/bytenode/issues/47). They also cause issues with the ndb debugger. See [#135](https://github.com/bytenode/bytenode/issues/135). It seems that whenever there is a context change (or even when called from another file or module), arrow functions break because `V8` inspects them internally using `Function.prototype.toString` in these cases. See [#157](https://github.com/bytenode/bytenode/issues/157).\n\n---\n\n## Resources\n\n* [How To Compile Node.js Code Using Bytenode](https://hackernoon.com/how-to-compile-node-js-code-using-bytenode-11dcba856fa9)\n* [Bytenode Webpack Plugin](https://github.com/herberttn/bytenode-webpack-plugin)\n* [Creating JS Binaries For Electron](https://www.jjeff.com/blog/2021/4/27/creating-javascript-binaries-for-electron)\n* [Electron Bytenode Example](https://github.com/spaceagetv/electron-bytenode-example)\n\n---\n\n## Bytenode CLI\n\n```console\n  Usage: bytenode [option] [ FILE... | - ] [arguments]\n\n  Options:\n    -h, --help                        show help information.\n    -v, --version                     show bytenode version.\n\n    -c, --compile [ FILE... | - ]     compile stdin, a file, or a list of files\n    --compress                        compress bytecode\n    -n, --no-module                   compile without producing commonjs module\n    -e, --electron                    compile for Electron\n    -ep, --electron-path              path to Electron executable\n\n    -l, --loader [ FILE | PATTERN ]   create a loader file and optionally define\n                                      loader filename or pattern using % as\n                                      filename replacer\n                                      defaults to %.loader.js\n    --no-loader                       do not create a loader file, conflicts\n                                      with -l\n    -t, --loader-type type            create a loader file of type commonjs or\n                                      module. Defaults to CommonJS\n\n  Examples:\n\n  $ bytenode -c script.js             compile `script.js` to `script.jsc`.\n  $ bytenode -c server.js app.js\n  $ bytenode -c src/*.js              compile all `.js` files in `src/` directory.\n\n  $ bytenode -c *.js -l %.load.js     create `filename.load.js` loader files along side `.jsc` files\n\n  $ bytenode script.jsc [arguments]   run `script.jsc` with arguments.\n  $ bytenode                          open Node REPL with bytenode pre-loaded.\n```\n\nExamples:\n\n* Compile `express-server.js` to `express-server.jsc`.\n\n```console\nuser@machine:~$ bytenode --compile express-server.js\n```\n\n* Run your compiled file `express-server.jsc`.\n\n```console\nuser@machine:~$ bytenode express-server.jsc\nServer listening on port 3000\n```\n\n* Compile all `.js` files in `./app` directory.\n\n```console\nuser@machine:~$ bytenode --compile ./app/*.js\n```\n\n* Compile all `.js` files in your project.\n\n```console\nuser@machine:~$ bytenode --compile ./**/*.js\n```\n\nNote: you may need to enable `globstar` option in bash (you should add it to `~/.bashrc`):\n`shopt -s globstar`\n\n* Starting from v1.0.0, bytenode can compile from `stdin`.\n\n```console\necho 'console.log(\"Hello\");' | bytenode --compile - \u003e hello.jsc\n```\n\n---\n\n## Bytenode API\n\n```javascript\nconst bytenode = require('bytenode');\n```\n\n---\n\n#### bytenode.compileCode(javascriptCode) → {Buffer}\n\nGenerates v8 bytecode buffer.\n\n* Parameters:\n\n| Name           | Type   | Description                                          |\n| ----           | ----   | -----------                                          |\n| javascriptCode | string | JavaScript source that will be compiled to bytecode. |\n\n* Returns:\n\n{Buffer} The generated bytecode.\n\n* Example:\n\n```javascript\nlet helloWorldBytecode = bytenode.compileCode(\n  `console.log('Hello World!');\n  43;  // this will be returned`\n);\n```\n\nThis `helloWorldBytecode` bytecode can be saved to a file. However, if you want to use your code as a module (i.e. if your file has some `exports`), you have to compile it using `bytenode.compileFile({compileAsModule: true})`, or wrap your code manually, using `Module.wrap()` function.\n\n---\n\n#### bytenode.compileElectronCode(javascriptCode, options) → {Promise\\\u003cBuffer\\\u003e}\n\nAsynchronous function which generates v8 bytecode buffer for Electron.\n\nSame as `bytenode.compileCode()`, but generates bytecode for the version of Electron currently installed in node_modules.\n\n* Parameters:\n\n| Name                   | Type   | Description                                          |\n| ----                   | ----   | -----------                                          |\n| javascriptCode         | string | JavaScript source that will be compiled to bytecode. |\n| options                | object | Options object.                                      |\n| options.electronPath   | string | Path to Electron executable.                         |\n\n* Returns:\n\n{Promise\\\u003cBuffer\\\u003e} A Promise which resolves with the generated bytecode.\n\n* Example:\n\n```javascript\nlet helloWorldBytecode = await bytenode.compileElectronCode(\n  `console.log('Hello World!');\n  43;  // this will be returned`\n);\n```\n\nThis `helloWorldBytecode` bytecode can be saved to a file. However, if you want to use your code as a module (i.e. if your file has some `exports`), you have to compile it using `bytenode.compileFile({compileAsModule: true})`, or wrap your code manually, using `Module.wrap()` function.\n\n---\n\n#### bytenode.runBytecode(bytecodeBuffer) → {any}\n\nRuns v8 bytecode buffer and returns the result.\n\n* Parameters:\n\n| Name           | Type   | Description                                                    |\n| ----           | ----   | -----------                                                    |\n| bytecodeBuffer | Buffer | The buffer object that was created using compileCode function. |\n\n* Returns:\n\n{any} The result of the very last statement executed in the script.\n\n* Example:\n\n```javascript\nconst result = bytenode.runBytecode(helloWorldBytecode);\n// prints: Hello World!\nconsole.log(result)\n// prints: 43\n```\n\n---\n\n#### bytenode.compileFile(args, output) → {Promise\\\u003cstring\\\u003e}\n\nAsynchronous function which compiles JavaScript file to .jsc file.\n\n* Parameters:\n\nName                 | Type              | Description\n----                 | ----              | -----------\nargs                 | object \\| string\nargs.filename        | string            | The JavaScript source file that will be compiled.\nargs.compileAsModule | boolean           | If true, the output will be a commonjs module. Default: true.\nargs.electron        | boolean           | If true, the output will be a compiled through Electron. Default: false.\nargs.electronPath    | string            | Path to Electron executable. Default: Electron binary from node_modules.\nargs.output          | string            | The output filename. Defaults to the same path and name of the original file, but with `.jsc` extension.\nargs.createLoader    | boolean \\| string | If true, create a CommonJS loader file.  As a string, select between `module` or `commonjs` loader. Default: `false`\nargs.loaderFilename  | string            | Filename or pattern for generated loader files. Defaults to originalFilename.loader.js. Use % as a substitute for originalFilename.\noutput               | string            | The output filename. (Deprecated: use args.output instead)\n\n* Returns:\n\n{Promise\\\u003cstring\\\u003e}: A Promise that resolves as the compiled filename.\n\n* Examples:\n\n```javascript\nlet compiledFilename = bytenode.compileFile({\n  filename: '/path/to/your/file.js',\n  output: '/path/to/compiled/file.jsc' // if omitted, it defaults to '/path/to/your/file.jsc'\n});\n```\n\nPrevious code will produce a commonjs module that can be required using `require` function.\n\n```javascript\nlet compiledFilename = await bytenode.compileFile({\n  filename: '/path/to/your/file.js',\n  output: '/path/to/compiled/file.jsc',\n  compileAsModule: false\n});\n```\n\nPrevious code will produce a direct `.jsc` file, that can be run using `bytenode.runBytecodeFile()` function. It can NOT be required as a module. Please note that `compileAsModule` MUST be `false` in order to turn it off. Any other values (including: `null`, `\"\"`, etc) will be treated as `true`. (It had to be done this way in order to keep the old code valid.)\n\n---\n\n#### bytenode.runBytecodeFile(filename) → {any}\n\nRuns .jsc file and returns the result.\n\n* Parameters:\n\n| Name     | Type   |\n| ----     | ----   |\n| filename | string |\n\n* Returns:\n\n{any} The result of the very last statement executed in the script.\n\n* Example:\n\n```javascript\n// test.js\nconsole.log('Hello World!');\n43;  // this will be returned\n```\n\n```javascript\nconst result = bytenode.runBytecodeFile('/path/to/test.jsc');\n// prints: Hello World!\nconsole.log(result)\n// prints: 43\n```\n\n---\n\n#### require(filename) → {any}\n\n* Parameters:\n\n| Name     | Type   |\n| ----     | ----   |\n| filename | string |\n\n* Returns:\n\n{any} exported module content\n\n* Example:\n\n```javascript\nlet myModule = require('/path/to/your/file.jsc');\n```\n\nJust like regular `.js` modules. You can also omit the extension `.jsc`.\n\n`.jsc` file must have been compiled using `bytenode.compileFile()`, or have been wrapped inside `Module.wrap()` function. Otherwise it won't work as a module and it can NOT be required.\n\nPlease note `.jsc` files must run with the same Node.js version that was used to compile it (using same architecture of course). Also, `.jsc` files are CPU-agnostic. However, you should run your tests before and after deployment, because V8 sanity checks include some checks related to CPU supported features, so this may cause errors in some rare cases.\n\n---\n\n## Acknowledgements\n\nI had the idea of this tool many years ago. However, I finally decided to implement it after seeing this [issue](https://github.com/nodejs/node/issues/11842) by @hashseed. Also, some parts were inspired by [v8-compile-cache](https://github.com/zertosh/v8-compile-cache) by @zertosh.\n","funding_links":[],"categories":["JavaScript","Repository","Library"],"sub_categories":["Source Code Obfuscator/Protect"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytenode%2Fbytenode","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytenode%2Fbytenode","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytenode%2Fbytenode/lists"}