{"id":13473072,"url":"https://github.com/hprose/hprose-nodejs","last_synced_at":"2025-04-05T12:08:49.514Z","repository":{"id":14179028,"uuid":"16885215","full_name":"hprose/hprose-nodejs","owner":"hprose","description":"Hprose is a cross-language RPC. This project is Hprose 2.0 for Node.js","archived":false,"fork":false,"pushed_at":"2019-04-19T08:33:26.000Z","size":833,"stargazers_count":300,"open_issues_count":8,"forks_count":88,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-29T11:11:39.631Z","etag":null,"topics":["cross-domain","cross-language","cross-platform","hprose","http","javascript","rpc","rpc-client","rpc-framework","rpc-library","rpc-server","rpc-service","serialization","serialization-library","serialize","tcp","tcp-client","tcp-server","unix-socket","websocket"],"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/hprose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-16T13:23:34.000Z","updated_at":"2025-02-25T13:31:02.000Z","dependencies_parsed_at":"2022-08-31T21:10:42.910Z","dependency_job_id":null,"html_url":"https://github.com/hprose/hprose-nodejs","commit_stats":null,"previous_names":[],"tags_count":55,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hprose%2Fhprose-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hprose%2Fhprose-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hprose%2Fhprose-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hprose%2Fhprose-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hprose","download_url":"https://codeload.github.com/hprose/hprose-nodejs/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246580463,"owners_count":20800110,"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":["cross-domain","cross-language","cross-platform","hprose","http","javascript","rpc","rpc-client","rpc-framework","rpc-library","rpc-server","rpc-service","serialization","serialization-library","serialize","tcp","tcp-client","tcp-server","unix-socket","websocket"],"created_at":"2024-07-31T16:01:00.506Z","updated_at":"2025-04-05T12:08:49.492Z","avatar_url":"https://github.com/hprose.png","language":"JavaScript","readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"http://hprose.com/banner.@2x.png\" alt=\"Hprose\" title=\"Hprose\" width=\"650\" height=\"200\" /\u003e\u003c/p\u003e\n\n\u003ca href=\"https://promisesaplus.com/\"\u003e\n    \u003cimg src=\"https://promisesaplus.com/assets/logo-small.png\" alt=\"Promises/A+ logo\" title=\"Promises/A+ 1.1 compliant\" align=\"right\" /\u003e\n\u003c/a\u003e\n\n# Hprose for Node.js\n\n[![Join the chat at https://gitter.im/hprose/hprose-nodejs](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](https://gitter.im/hprose/hprose-nodejs?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![npm download](https://img.shields.io/npm/dm/hprose.svg)](https://www.npmjs.com/package/hprose)\n[![optionalDependency Status](https://david-dm.org/hprose/hprose-nodejs/optional-status.svg)](https://david-dm.org/hprose/hprose-nodejs#info=optionalDependencies)\n[![npm version](https://img.shields.io/npm/v/hprose.svg)](https://www.npmjs.com/package/hprose)\n[![License](https://img.shields.io/npm/l/hprose.svg)](http://opensource.org/licenses/MIT)\n\n\u003e---\n- **[Introduction](#introduction)**\n- **[Usage](#usage)**\n    - **[Http Server](#http-server)**\n        - [Synchronous Functions or Methods](#synchronous-functions-or-methods)\n        - [Asynchronous Functions or Methods](#asynchronous-functions-or-methods)\n    - **[Http Client](#http-client)**\n        - [Exception Handling](#exception-handling)\n    - **[Tcp Server \u0026 Client](#tcp-server-client)**\n    - **[Unix Socket Server \u0026 Client](#unix-socket-server-client)**\n    - **[WebSocket Server \u0026 Client](#websocket-server-client)**\n\n\u003e---\n\n## Introduction\n\n*Hprose* is a High Performance Remote Object Service Engine.\n\nIt is a modern, lightweight, cross-language, cross-platform, object-oriented, high performance, remote dynamic communication middleware. It is not only easy to use, but powerful. You just need a little time to learn, then you can use it to easily construct cross language cross platform distributed application system.\n\n*Hprose* supports many programming languages, for example:\n\n* AAuto Quicker\n* ActionScript\n* ASP\n* C++\n* Dart\n* Delphi/Free Pascal\n* dotNET(C#, Visual Basic...)\n* Golang\n* Java\n* JavaScript\n* Node.js\n* Objective-C\n* Perl\n* PHP\n* Python\n* Ruby\n* ...\n\nThrough *Hprose*, You can conveniently and efficiently intercommunicate between those programming languages.\n\nThis project is the implementation of Hprose for Node.js.\n\nHprose 2.0 for Node.js Documents（中文版）: https://github.com/hprose/hprose-nodejs/wiki \n\n## Usage\n\n### Http Server\n\n#### Synchronous Functions or Methods\n\nHprose for Node.js is very easy to use. You can create a hprose server like this:\n\n```javascript\nvar hprose = require(\"hprose\");\nfunction hello(name) {\n    return \"Hello \" + name + \"!\";\n}\nvar server = hprose.Server.create(\"http://0.0.0.0:8080\");\nserver.addFunction(hello);\nserver.start();\n```\n\nTo start it use:\n\n    node --harmony server.js\n\n--harmony is a v8 options, hprose use it to optimize serialization.\nThis is not required option, but it is recommended to use it.\n\n#### Asynchronous Functions or Methods\n\nIn fact most nodejs service methods are asynchronous, you can publish asynchronous function like this:\n\n```javascript\nvar hprose = require(\"hprose\");\nfunction hello(name, callback) {\n    setTimeout(function() {\n        callback(\"Hello \" + name + \"!\");\n    }, 10);\n}\nvar server = hprose.Server.create(\"http://0.0.0.0:8080\");\nserver.addAsyncFunction(hello);\nserver.start();\n```\n\n### Http Client\n\nThen you can create a hprose client to invoke it like this:\n\n```javascript\nvar hprose = require(\"hprose\");\nvar client = hprose.Client.create(\"http://127.0.0.1:8080/\");\nvar proxy = client.useService();\nproxy.hello(\"world\", function(result) {\n    console.log(result);\n});\n```\n\nTo start it use:\n\n    node --harmony client.js\n\nor\n\n    node --harmony-proxies client.js\n\nWithout --harmony-proxies, you need create proxy like this:\n\n```javascript\nvar hprose = require(\"hprose\");\nvar client = hprose.Client.create(\"http://127.0.0.1:8080/\");\nvar proxy = client.useService([\"hello\"]);\nproxy.hello(\"world\", function(result) {\n    console.log(result);\n});\n```\n\nOr create client like this:\n\n```javascript\nvar hprose = require(\"hprose\");\nvar client = hprose.Client.create(\"http://127.0.0.1:8080/\", [\"hello\"]);\nclient.hello(\"world\", function(result) {\n    console.log(result);\n});\n```\n\n#### Exception Handling\n\nIf an error occurred on the server, or your service function/method throw an exception, it will be sent to the client. You need to pass an error callback function after succuss callback function to receive it. If you omit this callback function, the client will ignore the exception, like never happened.\n\nFor example:\n\n```javascript\nproxy.hello(\"world\", function(result) {\n    console.log(result);\n}, function(name, err) {\n    console.error(err);\n});\n```\n\n### Tcp Server \u0026 Client\n\nThe Tcp Server \u0026 Client are used as same as the Http Server \u0026 Client.\n\nTo create a Tcp Server:\n\n```javascript\nvar server = hprose.Server.create(\"tcp://0.0.0.0:4321\");\n```\n\nTo create a Tcp Client:\n\n```javascript\nvar client = hprose.Client.create('tcp://127.0.0.1:4321');\n```\n\n### Unix Socket Server \u0026 Client\n\nThe Unix Socket Server \u0026 Client are used as same as the Http Server \u0026 Client.\n\nTo create a Unix Socket Server:\n\n```javascript\nvar server = hprose.Server.create(\"unix:/tmp/my.sock\");\n```\n\nTo create a Unix Socket Client:\n\n```javascript\nvar client = hprose.Client.create('unix:/tmp/my.sock');\n```\n\n### WebSocket Server \u0026 Client\n\nThe WebSocket Server \u0026 Client are used as same as the Http Server \u0026 Client.\n\nTo create a WebSocket Server:\n\n```javascript\nvar server = hprose.Server.create(\"ws://0.0.0.0:8080/\");\n```\n\nTo create a WebSocket Client:\n\n```javascript\nvar client = hprose.Client.create('ws://0.0.0.0:8080/');\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhprose%2Fhprose-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhprose%2Fhprose-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhprose%2Fhprose-nodejs/lists"}