UNPKG

4.23 kBMarkdownView Raw
1[![npm](https://img.shields.io/npm/v/grpc.svg)](https://www.npmjs.com/package/grpc)
2# Node.js gRPC Library
3
4## PREREQUISITES
5- `node`: This requires `node` to be installed, version `4.0` or above. If you instead have the `nodejs` executable on Debian, you should install the [`nodejs-legacy`](https://packages.debian.org/sid/nodejs-legacy) package.
6
7- **Note:** If you installed `node` via a package manager and the version is still less than `4.0`, try directly installing it from [nodejs.org](https://nodejs.org).
8
9## INSTALLATION
10
11Install the gRPC NPM package
12
13```sh
14npm install grpc
15```
16
17## BUILD FROM SOURCE
18
19The following command can be used to build from source when installing the package from npm:
20
21```
22npm install grpc --build-from-source
23```
24
25The `--build-from-source` option will work even when installing another package that depends on `grpc`. To build only `grpc` from source, you can use the argument `--build-from-source=grpc`.
26
27## ABOUT ELECTRON
28
29The official electron documentation recommends to [build all of your native packages from source](https://electronjs.org/docs/tutorial/using-native-node-modules#modules-that-rely-on-node-pre-gyp). While the reasons behind this are technically good - many native extensions won't be packaged to work properly with electron - the gRPC source code is fairly difficult to build from source due to its complex nature, and we're also providing working electron pre-built binaries. Therefore, we recommend that you do not follow this model for using gRPC with electron. Also, for the same reason, `electron-rebuild` will always build from source. We advise you to not use this tool if you are depending on gRPC. Please note that there's not just one way to get native extensions running in electron, and that there's never any silver bullet for anything. The following instructions try to cater about some of the most generic ways, but different edge cases might require different methodologies.
30
31The best to get gRPC to work with electron is to do this, possibly in your `postinstall` script of your `package.json` file:
32
33```
34npm rebuild --target=2.0.0 --runtime=electron --dist-url=https://atom.io/download/electron
35```
36
37Note that the `2.0.0` above is the electron runtime version number. You will need to update this every time you go on a different version of the runtime.
38
39If you have more native dependencies than gRPC, and they work better when built from source, you can explicitely specify which extension to build the following way:
40
41```
42npm rebuild --build-from-source=sqlite3 --target=2.0.0 --runtime=electron --dist-url=https://atom.io/download/electron
43```
44
45This way, if you depend on both `grpc` and `sqlite3`, only the `sqlite3` package will be rebuilt from source, leaving the `grpc` package to use its precompiled binaries.
46
47## BUILD IN GIT REPOSITORY
48
49 1. Clone [the grpc-node Git Repository](https://github.com/grpc/grpc-node).
50 2. Run `git submodule update --init --recursive` from the repository root.
51 3. Run `cd packages/grpc-native-core`.
52 4. Run `npm install --build-from-source`.
53
54 - **Note:** On Windows, this might fail due to [nodejs issue #4932](https://github.com/nodejs/node/issues/4932) in which case, you will see something like the following in `npm install`'s output (towards the very beginning):
55
56 ```
57 ..
58 Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
59 WINDOWS_BUILD_WARNING
60 "..\IMPORTANT: Due to https:\github.com\nodejs\node\issues\4932, to build this library on Windows, you must first remove C:\Users\jenkins\.node-gyp\4.4.0\include\node\openssl"
61 ...
62 ..
63 ```
64
65 To fix this, you will have to delete the folder `C:\Users\<username>\.node-gyp\<node_version>\include\node\openssl` and retry `npm install`
66
67## CONFIGURE BINARIES' LOCATION
68
69You can configure the location from which the pre-compiled binaries are downloaded during installation.
70
71`npm install --grpc_node_binary_host_mirror=https://your-url.com`
72
73Or defining `grpc_node_binary_host_mirror` in your `.npmrc`.
74
75## API DOCUMENTATION
76
77See the [API Documentation](https://grpc.io/grpc/node/).
78
79## TESTING
80To run the test suite, simply run `npm test` in the install location.