Giter Club home page Giter Club logo

express-boilerplate's Introduction

Current travis build: build status โ€ƒ

A highly scalable and a focus on performance and best practices boilerplate code for Nodejs and TypeScript based web applications.

Start a new application in seconds!

Features

  • Quick scaffolding

    Create actions, routes, and models - right from the CLI using Plop micro-generator framework.

  • TypeScript

    The best way to write modern applications. Code is easier to understand. It is now way more difficult to write invalid code as was the case in dynamically typed languages

  • Dependency injection

    DI is a central part of any nontrivial application today and is the core of this project.

  • Static code analysis

    Focus on writing code, not formatting! Code formatter and linter keeps the code clean which makes work and communication with other developers more effective!

Note If you have discovered a bug or have a feature suggestion, feel free to create an issue on Github.

Don't forget to star or fork this if you liked it.

Configuration

After checkout of a repository, please perform the following steps in exact sequence:

  1. Copy docker-compose.override

    $ cp docker-compose.override.yml.dist docker-compose.override.yml
    
  2. Create .env file from .env.dist

    $ cp .env.dist .env
    

    Remember to fill up required values in .env

  3. Run npm i

  4. Run npm run docker-build

  5. Run watch - npm run watch

Dev setup

This app is fully dockerized, so in order to use it you have to have docker and docker-compose installed. What's more you need to have npm in order to run npm scripts.

  1. In order to run the whole app type:

    npm run start
    
  2. In order to watch files for dev purpose type:

    npm run watch
    
  3. If you need to close all containers run:

    npm run down
    
  4. To get into Docker container's shell:

    npm run shell
    

SonarQube configuration

Before deployment, please ensure that a related SonarQube project has been created. After that set proper repository variables (SONAR_TOKEN and SONAR_HOST_URL) and properties in sonar-project.properties file.

Code generation

We're using Plop for routes, models, actions, graphql (queries and mutations), commands and handlers generation.

npm run plop

Code style

We're using Prettier and ESLint to keep code clean. In order to reformat/check code run:

npm run lint
npm run format

Database migrations

Migrations should be stored inside migrations directory.

Easiest way to create a migration is to generate it from entity/ies:

npm run generate-migration

This should generate a migration for all connected entities.

Adminer setup

Adminer is configured in docker-compose.override.yml and should work out of the box on port 8080. To login to adminer use the following values:

Database type: postgres
Server: postgres
User: postgres
Password: password
Database: app

Of course, if any of this is changed via configuration or otherwise, then these changes must be reflected here as well.

GraphQL

Boilerplate has GraphQL support. Apollo server runs as a middleware and should be available locally under:

http://localhost:1337/graphql

To add new query/mutation run relevant plop commands and then:

  1. Modify schema.gql under graphql/schema.gql
  2. Run codegen: npm run generate-schema
  3. Restart watcher / API

Debugging

VS Code

There is launch.json configuration inside editors/vsc directory. Just copy it and create new debugger to make it work with vsc :)

Tests

There are two types of tests:

  • integration: npm run integration
  • units: npm run units

Issues:

If you notice any issues while using, let as know on github. Security issues, please sent on email

You may also like our other projects:

About us:

The Software House โ€ƒ tsh.png

License

license

This project is licensed under the terms of the MIT license.

express-boilerplate's People

Contributors

adamsmichal avatar andrzejtsh avatar arturwita avatar b-dabrowski avatar bdrozd-tsh avatar brzozitsh avatar dawidstezycki avatar grzesie2k avatar jbutrym-tsh avatar kamilkroltsh avatar klignowski avatar kuba9392 avatar low-cpu avatar marcinjanuszewski avatar mk-tsh avatar mkopa avatar paweltshdev avatar prosenkiewicz-tsh avatar qh4r avatar qh4r-tsh avatar retoxx-dev avatar rgolubowicz-tsh avatar roberuto avatar sebastian-drozd avatar sethii avatar sjedlikowski avatar szok avatar tobiasztsh avatar vviktorpl avatar wchodarcewicz 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

express-boilerplate's Issues

Move users to samples

Code in features/users isn't part of framework. Shouldn't be removed or moved to samples/examples?

Consider introducing new rule "force-return-await` to achieve better stack traces

Reason
In node.js 10 the result of code below will be different than in node 8.

const sleep = delay => new Promise(resolve => setTimeout(resolve, delay));
const test1 = async (a = 0) => {
    await sleep(10);
    if(a < 10) return test1(a+1);
    else console.trace('noawait', a);
};
test1();
const test2 = async (a = 0) => {
    await sleep(10);
    if(a < 10) return await test2(a+1);
    else console.trace('await', a);
};
test2();

119222214-7ce2f500-baf3-11eb-8cd5-03445f3a150a

Description
We should consider adding a custom rule which will force return await in functions.
However it isnt well optimized in node.js 12.

returnAwait: 1301.600ms
noReturnAwait: 1158.415ms

We should check how newer versions of node optimize it.

@CacheQuery decorator doesn't support nested queries

What is the issue?

As the issue's title states, there is a problem with nested queries for @CacheQuery decorator

Current behaviour

Let's assume that we have a query handler as described below:

export default class UsersQueryHandler implements QueryHandler<UsersQuery, UsersQueryResult> {
  public queryType: string = USERS_QUERY_TYPE;

  @CacheQuery({ duration: 60 })
  async execute(usersQuery: UsersQuery): Promise<UsersQueryResult> {
    return new UsersQueryResult({
      randomNumber: Math.random(),
    });
  }
}

our UsersQuery class looks like this:

export const USERS_QUERY_TYPE = "example/USERS";

export interface UsersQueryPayload {
  name?: string;
  surname?: string;
}

export class UsersQuery implements Query<UsersQueryPayload> {
  public type: string = USERS_QUERY_TYPE;

  constructor(public payload: UsersQueryPayload) {}
}

Now let's imagine that we are making query as stated below:

GET /api/example/example?name=bart&surname=baz

in such case, @CacheQuery decorator will construct a cache key for this query as given below:

Queries:UsersQueryHandler:[object Object]_example/USERS

That is the problem because the second query with different query params will be saved under the same cache key as the previous one (please note [object Object]).

Expected behaviour:

Different queries should be cached under different cache keys

Possible solution

I would suggest stringifying the queries so nested query objects will be saved under proper keys instead of [objet Object]

For example, if we would like to use JSON.stringify for stringifying the keys, then a cache key for given above query would look like this:

Queries:UsersQueryHandler:payload={"query":{"name":"bart","surname":"baz"}}_type="example/USERS"

Please see the attached PR for more details.

Node Prune does not work in new Macbook with M1 pro chip

executor failed running [/bin/sh -c apk add --no-cache bash curl git py-pip make && curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | sh && npm install node-dev -g && npm cache clean --force]: exit code: 1

This was the error I was getting. I changed the dockerfile to this

RUN apk add --no-cache bash curl git py-pip make &&
npm install node-dev -g && npm cache clean --force

RUN apk --no-cache add curl bash
RUN npx node-prune

to make it work

Missing blank line in Event template

There should be a blank line between class members in plop-templates/events/event.ts file:
7:3 error Expected blank line between class members lines-between-class-members

Integration tests

Throwing new error in execute method of custom CommandHandler will cause UnhandledPromiseRejectionWarning.

EventSubscriber template

Better to use a method than its hardcoded name to keep code more flexible. Also comments are unnecessary, because we want to generate a ready-tu-use subscriber, not an example.

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.