项目作者: akinmaurice

项目描述 :
Simple Node jS gRPC Server with Mongo DB
高级语言: JavaScript
项目地址: git://github.com/akinmaurice/node-grpc.git
创建时间: 2019-07-02T23:15:24Z
项目社区:https://github.com/akinmaurice/node-grpc

开源协议:

下载


node-grpc

Node JS GRPC Server with Express JS REST client using Mongo DB as database.

Getting started

Make sure you have at least Node.js 10.16.0 installed.

You can check your Node.js version by running node -v:

  1. $ node -v
  2. v10.16.0

clone

Navigate to your work directory and clone the project, change directory to the node-grpc and add a new remote origin pointing to the new project repo.

  1. $ git clone https://github.com/akinmaurice/node-grpc.git
  2. $ cd node-grpc

env

You can set environment variables using .env file, or setting them in your .bashrc or .zshrc file.

Using .env:
  1. $ touch .env
  1. # using any editor you prefer. (vim/nano/vi).
  2. $ vim .env

Paste the following configuration variables with their corresponding values.

  1. DATABASE_URI=VALUE
Using .bashrc or .zshrc:
  1. # open your bashrc or zshrc file,
  2. # using any editor you prefer. (vim/nano/vi).
  3. $ vim ~/.bashrc

Paste the following configuration variables with their corresponding values.

  1. DATABASE_URI=VALUE

Run command to reload

  1. $ source ~/.bashrc

Run command to install dependencies

  1. $ npm install

Run command to start server on port 50051

  1. $ npm run start-server

open a new terminal and run command to start client on port 3000

  1. $ npm run start-client

The above will get you a copy of the project up and running on your local machine for development and testing purposes.

Example Requests

Get List of all Todos

GET {{ base_uri }}/api/todos

Response

  1. {
  2. "todos": [
  3. {
  4. "id": "215782",
  5. "title": "Test Todo",
  6. "completed": false
  7. },
  8. {
  9. "id": "380484",
  10. "title": "Running Man Todo",
  11. "completed": false
  12. },
  13. {
  14. "id": "541088",
  15. "title": "Watch football",
  16. "completed": false
  17. }
  18. ]
  19. }

Get Single Todo

GET {{ base_uri }}/api/todos/:id

Response

  1. {
  2. "id": "609871",
  3. "title": "Test Todo",
  4. "completed": false
  5. }

Create new todo

POST {{ base_uri }}/api/todos

Request Query

parameters Type Description
title string Todo Title

Response

  1. {
  2. "id": "215782",
  3. "title": "Test Todo",
  4. "completed": false
  5. }

Delete Todo

DELETE {{ base_uri }}/api/todos/:id

Response

  1. {
  2. "status": "true"
  3. }

Used Technologies

  • gRPC
  • MongoDB with Mongoose
  • Node JS
  • Express JS

License

This project is licensed under the MIT License - see the LICENSE.md file for details