Thanks to visit codestin.com
Credit goes to github.com

Skip to content

cuulee/nodejs-api-starter

 
 

Repository files navigation

Node.js API Starter Kit  

Node.js API Starter Kit is a boilerplate and tooling for authoring data API backends with Node.js, JavaScript (via Babel) and GraphQL. It's meant to be paired with a web and/or mobile application project such as React Starter Kit.

Features

✓ Cross-platform, develope on macOS, Windows or Linux inside a Docker container
✓ No development dependencies except for Docker v1.12.5 or neweer
✓ Authentication and authorization via Passport.js (see src/passport)
✓ Session and cache management with Redis (see stop using JWT for sessions)
PostgreSQL database schema boilerplate and migration tools (see scripts, migrations)
GraphQL boilerplate, everything needed to get started building a GraphQL API endpoint
✓ The exact same process is used to build the app for production and build for running/testing locally

Directory Layout

.
├── /build/                     # The compiled output (via Babel)
├── /migrations/                # Database schema migrations
├── /scripts/                   # Build automation scripts
├── /src/                       # Node.js application source files
│   ├── /db/                    # Database access and connection pooling
│   ├── /passport/              # Passport.js authentication strategies
│   ├── /routes/                # Express routes, e.g. /login/facebook
│   ├── /types/                 # GraphQL types with resolve functions
│   │   ├── /User.js            # User account (id, email, etc.)
│   │   ├── /Viewer.js          # The top-level GraphQL object type
│   │   └── /...                # etc.
│   ├── /app.js                 # Express.js application
│   ├── /schema.js              # GraphQL schema
│   └── /server.js              # Node.js server (entry point)
├── /test/                      # Unit, integration and load tests
├── .env                        # Application settings for the dev environment
├── .env.example                # Available application settings as a reference
├── docker-compose.yml          # Defines Docker services, networks and volumes
├── Dockerfile                  # Commands for building a Docker image for production
├── package.json                # The list of project dependencies
└── yarn.lock                   # Fixed versions of all the dependencies

Getting Started

Make sure that you have Docker v1.12.5 or newer installed plus a good text editor or IDE (VS Code, WebStorm or another), clone the repo and launch the app with Docker Compose:

git clone -o nodejs-api-starter -b master --single-branch \
   https://github.com/kriasoft/nodejs-api-starter.git example-api
cd example-api
cp .env.example .env            # Copy environment variables from the template: '.env.example' -> '.env'
docker-compose up               # Launch Docker containers with the Node.js API app running inside

The API server must become available at http://localhost:5000/ (live demo).

Once the docker container named api is started, the Docker engine executes node scripts/run.js command that installs Node.js dependencies, migrates database schema to the latest version, compiles Node.js app from source files (see src) and launches it with "live reload" on port 5000 (see .env).

In order to open a new terminal session from inside the api Docker container run:

docker-compose exec api /bin/sh

From this shell you can run automation scripts such as yarn test, yarn run db:migrate etc. Find the full list of scripts available inside the scripts folder and the package.json file.

Testing

yarn run lint                   # Find problematic patterns in code
yarn run check                  # Check source code for type errors
yarn run test                   # Run unit tests once
yarn run test:watch             # Run unit tests in watch mode

Debugging

In order to run the app with V8 inspector enabled, simply set NODE_DEBUG=true flag in the .env file, restart the app (docker-compose up) and attach your debugger to 127.0.0.1:9229 (see .vscode/launch.json for VS Code as an example).

Deployment

Customize the deployment script found in scripts/publish.js on macOS/Linux or convert it to publish.cmd on Windows. Then whenever you need to deploy your app to a remote server simply run:

/bin/sh scripts/publish.sh      # or, `scripts/publish.cmd` on Windows

Not sure where to deploy your app? DigitalOcean is a great choice in many cases (get $10 credit)

Contributing

Anyone and everyone is welcome to contribute. Start by checking out the list of open issues marked help wanted. However, if you decide to get involved, please take a moment to review the guidelines.

Books and Tutorials

Docker in Action You Don't Know JS JavaScript Ninja Effective JavaScript NodeSchool.io

Related Projects

Support

License

Copyright © 2016-present Kriasoft, LLC. This source code is licensed under the MIT license found in the LICENSE.txt file. The documentation to the project is licensed under the CC BY-SA 4.0 license.


Made with ♥ by Konstantin Tarkus (@koistya, blog) and contributors

About

Boilerplate and tooling for authoring data API backends with Node.js and GraphQL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.7%
  • Shell 2.3%