{"id":20333278,"url":"https://github.com/protocolbuffers/protobuf-javascript","last_synced_at":"2026-02-24T09:27:53.540Z","repository":{"id":38380181,"uuid":"485902718","full_name":"protocolbuffers/protobuf-javascript","owner":"protocolbuffers","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-19T03:23:21.000Z","size":1313,"stargazers_count":411,"open_issues_count":73,"forks_count":72,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-04-12T14:14:43.825Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/protocolbuffers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-asserts.md","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":"2022-04-26T18:25:29.000Z","updated_at":"2025-04-11T17:00:26.000Z","dependencies_parsed_at":"2025-04-05T11:00:28.086Z","dependency_job_id":"f9a0dc5a-d299-4cb3-aaef-4cd314cd09e4","html_url":"https://github.com/protocolbuffers/protobuf-javascript","commit_stats":{"total_commits":396,"total_committers":78,"mean_commits":5.076923076923077,"dds":0.8308080808080808,"last_synced_commit":"566f35982a0a04718855f650e4496c2add001988"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protocolbuffers%2Fprotobuf-javascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protocolbuffers%2Fprotobuf-javascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protocolbuffers%2Fprotobuf-javascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/protocolbuffers%2Fprotobuf-javascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/protocolbuffers","download_url":"https://codeload.github.com/protocolbuffers/protobuf-javascript/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254041848,"owners_count":22004786,"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":[],"created_at":"2024-11-14T20:30:08.952Z","updated_at":"2026-01-16T20:16:49.305Z","avatar_url":"https://github.com/protocolbuffers.png","language":"JavaScript","readme":"Protocol Buffers - Google's data interchange format\n===================================================\n\nCopyright 2008 Google Inc.\n\nThis directory contains the JavaScript Protocol Buffers runtime library.\n\nThe library is currently compatible with:\n\n1. CommonJS-style imports (eg. `var protos = require('my-protos');`)\n2. Closure-style imports (eg. `goog.require('my.package.MyProto');`)\n\nSupport for ES6-style imports is not implemented yet.  Browsers can\nbe supported by using Browserify, webpack, Closure Compiler, etc. to\nresolve imports at compile time.\n\nTo use Protocol Buffers with JavaScript, you need two main components:\n\n1. The protobuf runtime library.  You can install this with\n   `npm install google-protobuf`, or use the files in this directory.\n    If npm is not being used, as of 3.3.0, the files needed are located in binary subdirectory;\n    arith.js, constants.js, decoder.js, encoder.js, map.js, message.js, reader.js, utils.js, writer.js\n2. The Protocol Compiler `protoc`.  This translates `.proto` files\n   into `.js` files.  The compiler is not currently available via\n   npm, but you can download a pre-built binary\n   [on GitHub](https://github.com/protocolbuffers/protobuf/releases)\n   (look for the `protoc-*.zip` files under **Downloads**).\n\n\n\nProject Status\n===\n\nAs of v4.0.0, you can directly install the `protoc-gen-js` plugin from npm as\n[@protocolbuffers/protoc-gen-js](https://www.npmjs.com/package/@protocolbuffers/protoc-gen-js).\n\n**Support Status**\n\nWe currently do not have staffing for more than minimal support for this open\nsource project. We will answer questions and triage any issues.\n\n**Contributing**\n\nContributions should preserve existing behavior where possible. Current\ncustomers rely on applications continuing to work across minor version upgrades.\nWe encourage small targeted contributions. Thanks!\n\n\nSetup\n=====\n\nFirst, obtain the Protocol Compiler.  The easiest way is to download\na pre-built binary from [https://github.com/protocolbuffers/protobuf/releases](https://github.com/protocolbuffers/protobuf/releases).\n\nIf you want, you can compile `protoc` from source instead.  To do this\nfollow the instructions in [the top-level\nREADME](https://github.com/protocolbuffers/protobuf/blob/main/src/README.md).\n\nOnce you have `protoc` compiled, you can run the tests provided along with our\nproject to examine whether it can run successfully. In order to do this, you\nshould download the Protocol Buffer source code from the release page with the\nlink above. Then extract the source code and navigate to the folder named `js`\ncontaining a `package.json` file and a series of test files. In this folder, you\ncan run the commands below to run the tests automatically.\n\n    $ npm install\n    $ PROTOC_INC=/usr/include/google/protobuf npm test\n\n`PROTOC_INC` specifies the protobuf include path. By default, we use `protoc`\nlocated from `PATH`. Optionally, you can use the `PROTOC` enviroment variable to\nspecify an alternative `protoc`.\n\nThis will run two separate copies of the tests: one that uses\nClosure Compiler style imports and one that uses CommonJS imports.\nYou can see all the CommonJS files in `commonjs_out/`.\nIf all of these tests pass, you know you have a working setup.\n\n\nUsing Protocol Buffers in your own project\n==========================================\n\nTo use Protocol Buffers in your own project, you need to integrate\nthe Protocol Compiler into your build system.  The details are a\nlittle different depending on whether you are using Closure imports\nor CommonJS imports:\n\nClosure Imports\n---------------\n\nIf you want to use Closure imports, your build should run a command\nlike this:\n\n    $ protoc --js_out=library=myproto_libs,binary:. messages.proto base.proto\n\nFor Closure imports, `protoc` will generate a single output file\n(`myproto_libs.js` in this example).  The generated file will `goog.provide()`\nall of the types defined in your .proto files.  For example, for the unit\ntests the generated files contain many `goog.provide` statements like:\n\n```js\ngoog.provide('proto.google.protobuf.DescriptorProto');\ngoog.provide('proto.google.protobuf.DescriptorProto.ExtensionRange');\ngoog.provide('proto.google.protobuf.DescriptorProto.ReservedRange');\ngoog.provide('proto.google.protobuf.EnumDescriptorProto');\ngoog.provide('proto.google.protobuf.EnumOptions');\n```\n\nThe generated code will also `goog.require()` many types in the core library,\nand they will require many types in the Google Closure library.  So make sure\nthat your `goog.provide()` / `goog.require()` setup can find all of your\ngenerated code, the core library `.js` files in this directory, and the\nGoogle Closure library itself.\n\nOnce you've done this, you should be able to import your types with\nstatements like:\n\n```js\ngoog.require('proto.my.package.MyMessage');\n\nvar message = proto.my.package.MyMessage();\n```\n\nIf unfamiliar with Closure or its compiler, consider reviewing\n[Closure documentation](https://github.com/google/closure-library).\n\nCommonJS imports\n----------------\n\nIf you want to use CommonJS imports, your build should run a command\nlike this:\n\n    $ protoc --js_out=import_style=commonjs,binary:. messages.proto base.proto\n\nFor CommonJS imports, `protoc` will spit out one file per input file\n(so `messages_pb.js` and `base_pb.js` in this example).  The generated\ncode will depend on the core runtime, which should be in a file called\n`google-protobuf.js`.  If you are installing from `npm`, this file should\nalready be built and available.  If you are running from GitHub, you need\nto build it first by running:\n\n    $ gulp dist\n\nOnce you've done this, you should be able to import your types with\nstatements like:\n\n```js\nvar messages = require('./messages_pb');\n\nvar message = new messages.MyMessage();\n```\n\nThe `--js_out` flag\n-------------------\n\nThe syntax of the `--js_out` flag is:\n\n    --js_out=[OPTIONS:]output_dir\n\nWhere `OPTIONS` are separated by commas.  Options are either `opt=val` or\njust `opt` (for options that don't take a value).  The available options\nare specified and documented in the `GeneratorOptions` struct in\n[generator/js_generator.h](https://github.com/protocolbuffers/protobuf-javascript/blob/main/generator/js_generator.h#L53).\n\nSome examples:\n\n- `--js_out=library=myprotos_lib.js,binary:.`: this contains the options\n  `library=myprotos.lib.js` and `binary` and outputs to the current directory.\n  The `import_style` option is left to the default, which is `closure`.\n- `--js_out=import_style=commonjs,binary:protos`: this contains the options\n  `import_style=commonjs` and `binary` and outputs to the directory `protos`.\n  `import_style=commonjs_strict` doesn't expose the output on the global scope.\n\nAPI\n===\n\nThe API is not well-documented yet.  Here is a quick example to give you an\nidea of how the library generally works:\n\n```js\nvar message = new MyMessage();\n\nmessage.setName(\"John Doe\");\nmessage.setAge(25);\nmessage.setPhoneNumbers([\"800-555-1212\", \"800-555-0000\"]);\n\n// Serializes to a UInt8Array.\nvar bytes = message.serializeBinary();\n\nvar message2 = MyMessage.deserializeBinary(bytes);\n```\n\nFor more examples, see the tests.  You can also look at the generated code\nto see what methods are defined for your generated messages.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprotocolbuffers%2Fprotobuf-javascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprotocolbuffers%2Fprotobuf-javascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprotocolbuffers%2Fprotobuf-javascript/lists"}