{"_id":"@apachedubbo/dubbo-node","name":"@apachedubbo/dubbo-node","dist-tags":{"alpha":"3.0.0-alpha","latest":"3.0.0-alpha"},"versions":{"3.0.0-alpha":{"name":"@apachedubbo/dubbo-node","version":"3.0.0-alpha","license":"Apache-2.0","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-node"},"scripts":{"clean":"rm -rf ./dist/cjs/* ./dist/esm/* ./dist/types/*","build":"npm run build:cjs && npm run build:esm+types","build:cjs":"tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'","build:esm+types":"tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/types","jasmine":"jasmine --config=jasmine.json"},"main":"./dist/cjs/index.js","type":"module","types":"./dist/types/index.d.ts","exports":{"types":"./dist/types/index.d.ts","import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"engines":{"node":">=16.0.0"},"dependencies":{"@apachedubbo/dubbo":"3.0.0-alpha","headers-polyfill":"^3.1.2"},"peerDependencies":{"@bufbuild/protobuf":"^1.2.1"},"devDependencies":{"@types/jasmine":"^4.3.1","jasmine":"^5.0.0"},"gitHead":"dd9eba1b7b4c5d306fc8275537694cca02ad7975","description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and  [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to  TypeScript.","bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"homepage":"https://github.com/apache/dubbo-js#readme","_id":"@apachedubbo/dubbo-node@3.0.0-alpha","_nodeVersion":"18.16.1","_npmVersion":"9.5.1","dist":{"integrity":"sha512-OiBJIbun8JVdyHNrbpq8irb3xdZsqfMPh9ZcO5xyTQfTicc355vA079AOZznR005bvGSU9Tk8cWQe7FtQfMN1A==","shasum":"1c6f5296226774dd8628148e156d41a0786b2c80","tarball":"https://registry.npmjs.org/@apachedubbo/dubbo-node/-/dubbo-node-3.0.0-alpha.tgz","fileCount":57,"unpackedSize":344338,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCL5tPz5QSAVsw2RUH08jkkKg3/mnGqe1dgi0WqkkI86wIgIzaHGfcH4t4KUY+7bP6aCs85hZAGtngSwqFYCuaCVdY="}]},"_npmUser":{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},"directories":{},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/dubbo-node_3.0.0-alpha_1694061524740_0.5786387225442273"},"_hasShrinkwrap":false}},"time":{"created":"2023-09-07T04:38:44.659Z","3.0.0-alpha":"2023-09-07T04:38:45.069Z","modified":"2023-09-07T04:38:45.371Z"},"maintainers":[{"name":"jianyi-gronk","email":"jianyi_gronk@163.com"},{"name":"apache-dubbo","email":"dubbo.alibaba@gmail.com"}],"description":"Dubbo is a family of libraries for building and consuming APIs on different languages and platforms, and  [@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to  TypeScript.","homepage":"https://github.com/apache/dubbo-js#readme","repository":{"type":"git","url":"git+https://github.com/apache/dubbo-js.git","directory":"packages/dubbo-node"},"bugs":{"url":"https://github.com/apache/dubbo-js/issues"},"license":"Apache-2.0","readme":"# @apachedubbo/dubbo-node\n\nDubbo is a family of libraries for building and consuming APIs on different languages and platforms, and \n[@apachedubbo/dubbo](https://www.npmjs.com/package/@apachedubbo/dubbo) brings type-safe APIs with Protobuf to \nTypeScript.\n\n`@apachedubbo/dubbo-node` provides the following adapters for Node.js:\n\n### createDubboTransport()\n\nLets your clients running on Node.js talk to a server with the Dubbo protocol:\n\n```diff\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\n+ import { createDubboTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\n+ // A transport for clients using the Dubbo protocol with Node.js `http` module\n+ const transport = createDubboTransport({\n+   baseUrl: \"https://demo.connect.build\",\n+   httpVersion: \"1.1\"\n+ });\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\n### createGrpcTransport()\n\nLets your clients running on Node.js talk to a server with the gRPC protocol:\n\n```diff\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\n+ import { createGrpcTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\n+ // A transport for clients using the gRPC protocol with Node.js `http2` module\n+ const transport = createGrpcTransport({\n+   baseUrl: \"https://demo.connect.build\",\n+   httpVersion: \"2\"\n+ });\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\n### createGrpcWebTransport()\n\nLets your clients running on Node.js talk to a server with the gRPC-web protocol:\n\n```diff\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\n+ import { createGrpcWebTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\n+ // A transport for clients using the Dubbo protocol with Node.js `http` module\n+ const transport = createGrpcWebTransport({\n+   baseUrl: \"https://demo.connect.build\",\n+   httpVersion: \"1.1\"\n+ });\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\n\n### dubboNodeAdapter()\n\nRun your Dubbo RPCs on the Node.js `http`, `https`, or `http2` modules.\n\n```ts\n// connect.ts\nimport { DubboRouter } from \"@apachedubbo/dubbo\";\n\nexport default function(router: DubboRouter) {\n  // implement rpc Say(SayRequest) returns (SayResponse)\n  router.rpc(ElizaService, ElizaService.methods.say, async (req) => ({\n    sentence: `you said: ${req.sentence}`,\n  }));\n}\n```\n\n```diff\n// server.ts\nimport * as http2 from \"http2\";\n+ import routes from \"dubbo\";\n+ import { dubboNodeAdapter } from \"@apachedubbo/dubbo-node\";\n\nhttp2.createServer(\n+ dubboNodeAdapter({ routes }) // responds with 404 for other requests\n).listen(8080);\n```\n\n\nWith that server running, you can make requests with any gRPC, gRPC-Web, or Dubbo client.\n\n`buf curl` with the gRPC protocol:\n\n```bash\nbuf curl --schema buf.build/bufbuild/eliza \\\n  --protocol grpc --http2-prior-knowledge \\\n  -d '{\"sentence\": \"I feel happy.\"}' \\\n  http://localhost:8080/buf.connect.demo.eliza.v1.ElizaService/Say\n```\n\n`curl` with the Dubbo protocol:\n\n```bash\ncurl \\\n    --header \"Content-Type: application/json\" \\\n    --data '{\"sentence\": \"I feel happy.\"}' \\\n     --http2-prior-knowledge \\\n    http://localhost:8080/buf.connect.demo.eliza.v1.ElizaService/Say\n```\n\nNode.js with the gRPC protocol:\n\n```ts\nimport { createPromiseClient } from \"@apachedubbo/dubbo\";\nimport { createGrpcTransport } from \"@apachedubbo/dubbo-node\";\nimport { ElizaService } from \"./gen/eliza_dubbo.js\";\n\nconst transport = createGrpcTransport({\n  baseUrl: \"http://localhost:8080\",\n  httpVersion: \"2\",\n});\n\nconst client = createPromiseClient(ElizaService, transport);\nconst { sentence } = await client.say({ sentence: \"I feel happy.\" });\nconsole.log(sentence) // you said: I feel happy.\n```\n\nA client for the web browser actually looks identical to this example - it would\nsimply use `createDubboTransport` from [@apachedubbo/dubbo-web](https://www.npmjs.com/package/@apachedubbo/dubbo-web) \ninstead.\n\n\n## Getting started\n\nTo get started with Dubbo, head over to the [docs](https://cn.dubbo.apache.org/zh-cn/overview/quickstart/) \nfor a tutorial, or take a look at [our example](https://github.com/apache/dubbo-js/tree/dubbo3/example/). \n","readmeFilename":"README.md"}