Skip to content

lorimccurry/node-express-starter

Repository files navigation

Forks Stargazers LinkedIn


A starter Express app with all the goodies to get you up and running quickly!

Table of Contents
  1. About The Project
  2. Getting Started
  3. Prisma-Docker Tips
  4. Make Commands
  5. Starter Endpoints
  6. Database GUI Connections
  7. Roadmap
  8. Contributing
  9. Contact

About The Project

Built With

(back to top)

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

  1. npm
npm install npm@latest -g
  1. Postgres (a couple suggestions to get started)
  1. Postgres requirements:
  • Start your server
  • Confirm the default user is present or create a new one with the ability to Create DB
  1. Create a .env. and .env.test using .env.example and .env.test.example and populate with your information
  • TIP: notice the various database connection urls in .env.example especially. Connecting with Prisma inside a Docker container can be a little tricky.
  1. Install Docker desktop

  2. Other handy tools:

  • Postman or similar API Management tool
  • A database GUI tool compatible with Postgres (such as TablePlus)

Installation

  1. Clone the repo
    git clone https://github.com/lorimccurry/node-express-starter.git
  2. Install NPM packages
    npm install
  3. Building Docker containers for local dev/test
    make build
    make up-with-test
  4. Containers that should be running:
  1. Starting Prisma Dev Client
  • enter node_backend container
     docker exec -it node_backend /bin/sh
  • from inside the container start the prisma client and make the database current (should contain a User table when complete)
     npm run init-prisma-dev
  1. Starting Prisma Test Client
  • enter node_backend_test container

     docker exec -it node_backend_test /bin/sh
  • from inside the container:

    • start the prisma client and make the database current (should contain a User table when complete)
     npm run init-prisma-test
    • run existing test suite with either command:
     npm test
    jest

(back to top)

Prisma-Docker Tips

Most of the Prisma documentation and examples are geared for local development, and not Docker development. A few tips:

  • The Prisma connection string (in your various .env files) is key to getting Prisma to know about your database. For it to work in Docker, the host is the name of the postgres db container you want to connect with.
  • You will run Prisma migrations and other Prisma commands from INSIDE the given node backend container. Prisma commands will not work outside of containers and will complain it can't find your database. Node container access command:
docker exec -it container_name /bin/sh
  • You also will run test commands from inside the node_backend_test container, or similar to the above point, Prisma will not know about your test db.
  • The project is geared for Docker development, but you can run it locally. Uncomment the Prisma connection url in .env to either of the local options. The scripts in package.json should work locally. (ie: npm run dev, etc). You will need to create local databases if you develop outside of the docker containers.
  • If things ever get weird with your database, you can nuke the docker volume (and all your data!) with the following bash script. It is included in the make build command as well.
bash clean_pgdata.sh

(back to top)

Make Commands

This project has a Makefile to make (ha) for easier commands. Please take a look as not all commands have been noted in this README.

(back to top)

Starter Endpoints

Starter endpoints for "gut check" and auth have already been created for you. The auth endpoints are tested.

Postman collection:

Run in Postman

  1. Gut check:
  1. Auth
{
  "email": "e@email.com",
  "password": "password"
}
  • 201 response body
{
  "id": 1,
  "createdAt": "2022-04-09T19:57:11.119Z",
  "updatedAt": "2022-04-09T19:57:11.119Z",
  "email": "e@email.com",
  "name": null
}
  1. Logger
  • http://localhost:8000/v1/logger
  • Endpoint for show/test purposes only. Delete as desired (don't ship to prod!).
  • Shows logging with Winston
  • Has middleware auth protection on the route to demonstrate/test verifyToken in /utils/auth.ts
  • 401 if you are not logged in
  • 201 and logging info if you are logged in

(back to top)

Database GUI connections

Database connections with Prisma can be a little tricky as you have to connect to the database via the Docker container.

  1. Dev db connection info:
  • Host/Socket: 0.0.0.0
  • Port: 5433
  • user: Your user from your .env file
  • password: Your password from your .env file
  • database: prisma
  1. Test db connection info
  • Host/Socket: 0.0.0.0
  • Port: 5434
  • user: Your user from your .env.test file
  • password: Your password from your .env.test file
  • database: test
  1. If you connect without using Docker (make sure to adjust the connection url in your .env file):
  • Host/Socket: 127.0.0.1
  • Port: 5432
  • user: Your user from your .env file
  • password: Your password from your .env file
  • database: prisma

(back to top)

Roadmap

  • Google Auth support
  • /signout endpoint
  • Support for prod/deployment
  • CI/CD support

(back to top)

Contributing

Thank you for your interest in this project - it is greatly appreciated. It isn't quite ready for contributions yet as it's still under heavy development. Please give it a star if you like!

(back to top)

Contact

Lori McCurry - lori.mccurry@gmail.com

About

A starter Express app with all the goodies to get you up and running reliably and quickly!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published