Giter Site home page Giter Site logo

ngduc / node-rem Goto Github PK

View Code? Open in Web Editor NEW
240.0 8.0 50.0 8.35 MB

Node REM - NodeJS Rest Express MongoDB and more: typescript, passport, JWT, socket.io, HTTPS, HTTP2, async/await, nodemailer, templates, pagination, docker, etc. Live Demo: https://node-rem-ngduc.vercel.app

License: MIT License

Dockerfile 0.16% Shell 0.89% TypeScript 96.27% HTML 1.69% JavaScript 0.40% CSS 0.60%
nodejs rest-api express mongoose mongodb typescript boilerplate es6 es2017 express-boilerplate microservices

node-rem's Introduction

Node REM

NodeJS Rest Express MongoDB (REM) - a production-ready lightweight backend setup.

Build Status Maintainability

Live Demo (login with a test user: [email protected], user111 - inspect API calls to learn more)

๐ŸŒŸ It rains cats and dogs features:

  Typescript      Express   CORS     Helmet    DotEnv   joi (validation)   forever
  Mongoose        Passport  JWT      Await
  Tslint          Apidoc    Docker   Husky    Morgan    Travis   Unix/Mac/Win (Powershell)
  Tests
            Mocha  Chai     Sinon    istanbul
  MORE:
            HTTPS           HTTP2 (spdy)      Socketio 2.1       Init DB Data
            Slack message   Nodemailer        Mailgun            Email Templates    Forgot Password
            VSCode Debug    Dependabot        Codacy             File upload (multer)
      API
            API response    (data, meta: limit, offset, sort)    Transform res
            apiJson         Pagination query
            Regex query     Whitelist fields in response         Populate deep fields
            mstime          API response time     Stack trace in Response
      UI Example
            CRA, Typescript, React-router, Axios, PostCSS, Tailwind. Components: Login, Home, ItemView.
            Portable-react

๐Ÿ“ฆ Installation

Require: MongoDB and NodeJS v8.12.0 +

Clone this project:

git clone https://github.com/ngduc/node-rem.git your-app
cd your-app
rm -rf .git   (remove this github repo's git settings)
yarn
  • Update package.json and .env file with your information.
  • Run yarn dev, it will create a new Mongo DB "node-rem"
  • Verify yarn test can run all unit tests.
  • Verify: use Postman to POST http://localhost:3009/api/v1/auth/register to create a new user. (set payload to have email, password)
curl -k -d '{"email": "[email protected]", "password": "testpsw"}' -H "Content-Type: application/json" -X POST http://localhost:3009/api/v1/auth/register

๐Ÿ”ง Commands

- Start MongoDB first. Verify .env variables.

yarn dev      launch DEV mode
yarn start    launch PROD mode
yarn stop

yarn test     Run tests   (requires MongoDB)

Frontend Example - uses this node-rem backend:

- First, start the Backend with: yarn dev

- Then, start UI:
cd ./ui
yarn
yarn start    (then open http://localhost:3000 - login with a test user: [email protected], user111)

๐Ÿ“– Features

Your simple API Route Handler will have a nice syntax like this: (packed with vitamins cool stuffs)

exports.list = async (req: Request, res: Response, next: NextFunction) => {
  try {
    const data = (await User.list(req)).transform(req); // query & run userSchema.transform() for response
    apiJson({ req, res, data, model: User }); // return standard API Response
  } catch (e) {
    next(e);
  }
};

API Response is similar to JSON API standard:

GET http://localhost:3009/api/v1/users?fields=id,email&email=*user1* (get id & email only in response)
GET http://localhost:3009/api/v1/users?page=1&perPage=20 (query & pagination)
GET http://localhost:3009/api/v1/users?limit=5&offset=0&sort=email:desc,createdAt
{
    "meta": {
        "limit": 5,
        "offset": 0,
        "sort": {
            "email": -1,
            "createdAt": 1
        },
        "totalCount": 4,
        "timer": 3.85,
        "timerAvg": 5.62
    },
    "data": [
        {
            "id": "5bad07cdc099dfbe49ef69d7",
            "name": "John Doe",
            "email": "[email protected]",
            "role": "user",
            "createdAt": "2018-09-27T16:39:41.498Z"
        },
        // more items...
    ]
}

Example of generated API Docs (using apidoc) - https://node-rem.netlify.com

๐Ÿ“– Documentation

๐Ÿ™Œ Thanks

All contributions are welcome!

UI Example uses Portable-react

node-rem's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar greenkeeper[bot] avatar jipingwang avatar ngduc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-rem's Issues

environment yml indentation

Build steps currently fail early do to incorrect indentation of environment:

docker-compose.dev.yml
docker-compose.prod.yml

version: "2"
services:
  boilerplate-api:
    command: yarn dev -- -L
  environment:
    - NODE_ENV=development

should be

version: "2"
services:
  boilerplate-api:
    command: yarn dev -- -L
    environment:
      - NODE_ENV=development

Error on dev

Great looking project! Seem to get an error on dev however

yarn docker:dev

output...

[5/5] Building fresh packages...
$ cd ./node_modules && node ../package_symlinks.js && cd ..
module.js:550
    throw err;
    ^

Error: Cannot find module '/app/package_symlinks.js'
    at Function.Module._resolveFilename (module.js:548:15)
    at Function.Module._load (module.js:475:25)
    at Function.Module.runMain (module.js:694:10)
    at startup (bootstrap_node.js:204:16)
    at bootstrap_node.js:625:3
error Command failed with exit code 1.

many path Error: Cannot find module '../xxx'

many modules not found

Error: Cannot find module 'xxx'

  • Error: Cannot find module '../models/refreshToken.model'
  • ... many more like this

Environment Details

  • OS: Windows 10
  • Node.js version: v8.12.0
  • npm version: 6.4.1

Long Description

  • I manually updated some, but it seems i need to configure something?

bug: query validation

If the query is:
http://localhost:3009/v1/users?role=admin&limit=5&offset=0&sort=email:desc,createdAt
shouldn't validation be:

listUsers: {
    query: Joi.object({
      page: Joi.number().min(1),
      perPage: Joi.number().min(1).max(100),
      limit: Joi.number().min(1),
      offset: Joi.number().min(1),
      role: Joi.string().valid(...User.roles),
      sort: Joi.string(),
    })
  }

instead of:

listUsers: {
    query: Joi.object({
      page: Joi.number().min(1),
      perPage: Joi.number().min(1).max(100),
      name: Joi.string(),
      email: Joi.string(),
      role: Joi.string().valid(...User.roles)
    })
  }

I might be wrong but the second one doesn't work for me, it gives - validation error

Not run with Node 15

it stuck here.

yarn run v1.22.4
$ npx nodemon --watch 'src/**/*.ts' --ignore 'src/**/*.spec.ts' --exec ts-node --files src/index.ts
[nodemon] 2.0.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): src/config/express.ts
[nodemon] watching extensions: ts,json
[nodemon] starting `ts-node src/config/mongoose.ts src/config/passport.ts src/config/vars.ts --files src/index.ts`
[nodemon] clean exit - waiting for changes before restart

switch back to 12 works well

1

2

1

2

add logout method

add logout method

  • feature: please add logout route with logout management.!

Short Description:

  • Unable to set logout to server

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.