edevil / node-webapp-sample

Experimental starter pack for Node.JS webapps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-webapp-sample

Experimental starter pack for Node.JS webapps

TODO

  1. GraphQL resolver middleware rate limit (https://github.com/microlinkhq/async-ratelimiter) (https://github.com/prisma/graphql-middleware)
  2. GraphQL shield (https://github.com/maticzav/graphql-shield)

Migrations

Create migrations

npm run typeorm -- migration:generate -n Initial

Run migrations

npm run typeorm -- migration:run

Postgres extensions needed

  1. uuid-ossp
  2. unaccent
  3. pg_trgm

Helm package

noder/

Features

  • Dialect: Typescript Link
  • Server: Koa Link
  • ORM: TypeORM Link
  • GraphQL: Apollo Link
  • GraphQL: Uploads Link
  • OAuth provider Link
  • HTML templating: Nunjucks Link
  • HTTP Sessions Link
  • Tests: Jest Link
  • Authentication: Passport Link
  • Structured logging: Winston Link
  • Tracing: AsyncHooks Link
  • Exception reporting: Sentry Link
  • i18n Link
  • Rate limiting Link
  • Security: CSRF, CORS, etc
  • Linting: TSLint, prettier
  • Websockets: socket.io Link
  • Multipart uploads: async-busboy Link
  • Full text search
  • Flash messages
  • Production deployment config suited for Kubernetes
  • Dockerfile
  • Helm package (noder)

Dependencies

Quickstart

PostgreSQL

docker run -d --name=database -p 5432:5432 -e POSTGRES_DB=sample_db postgres

Redis

docker run -d -p 6379:6379 --name shared_redis redis

NPM dependencies

npm install

Config variables

  • APP_KEYS: JSON array of strings that is used as secrets for various functions. Make sure this is initialized with random secret data.
  • BASE_URL: Base URL that is used to build absolute URLs pointing to this application. Default: "http://example.com:3000"
  • DB_HOST: Hostname of the database. Default: "localhost"
  • DB_NAME: Name of the database (needs to exist). Default: "sample_db"
  • DB_PASSWORD: Password to connect to database: Default: ""
  • DB_USER: Username to connect to database: Default: "postgres"
  • GOOGLE_CLIENT_ID: Google client ID for Google authentication.
  • GOOGLE_CLIENT_SECRET: Google client secret for Google authentication.
  • GQL_DEPTH_LIMIT: Depth limit for GraphQL queries. Default: "5"
  • GQL_MAX_PER_PAGE: Max items per page on GraphQL queries. Default: "100"
  • GQL_PATH: Path on where to mount GraphQL handler. Default: "/graphql"
  • LOG_SQL: Log all SQL queries. Default: "true"
  • ORIGINS: JSON array of allowed request origins. Default: "http://localhost:3000", "http://example.com:3000"
  • PORT: Post to listen on. Default: "3000"
  • RAVEN_DSN: DSN to use for reporting exceptions.
  • REDIS_HOST: Hostname of the Redis server. Default: "localhost"
  • REDIS_PREFIX: Redis prefix to use. Default: "sample-node"
  • SHOW_PLAYGROUND: Show GraphQL playground. Default: "true"
  • TRUST_X_HEADERS: Trust proxy headers. Default: "false"

The dotenv module is used so a .env file can be placed on the root of the project with values for these enviroment variables.

Run application

npm start

Available commands

  • npm start: Start application in development mode.
  • npm test: Run tests.
  • npm run build: Compile Typescript code and generate production build in dist/.
  • npm run lint: Run TSLint on all the code.
  • npm run pretty: Check all the code against prettier's standards.

GraphQL examples

Subscribe for new cards

subscription {
  cardAdded {
    title
  }
}

Add new card

mutation {
  createCard(card:{title:"Title", description:"Description"}) {
    id
  }
}

List cards

{
  cards {
    id
    title
  }
}

Known issues

About

Experimental starter pack for Node.JS webapps

License:MIT License


Languages

Language:TypeScript 92.8%Language:HTML 5.2%Language:Mustache 1.4%Language:Dockerfile 0.6%