Table of Contents
To get a local copy up and running follow these simple example steps.
- npm
npm install npm@latest -g
- Postgres (a couple suggestions to get started)
- Postgres requirements:
- Start your server
- Confirm the default user is present or create a new one with the ability to
Create DB
- 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.
-
Other handy tools:
- Postman or similar API Management tool
- A database GUI tool compatible with Postgres (such as TablePlus)
- Clone the repo
git clone https://github.com/lorimccurry/node-express-starter.git
- Install NPM packages
npm install
- Building Docker containers for local dev/test
make build
make up-with-test
- Containers that should be running:
node_backend
on http://localhost:8000node_backend_test
on http://localhost:4000development-db
test_db
- Starting Prisma Dev Client
- enter
node_backend
containerdocker 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
- Starting Prisma Test Client
-
enter
node_backend_test
containerdocker 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
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 inpackage.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
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.
Starter endpoints for "gut check" and auth have already been created for you. The auth endpoints are tested.
Postman collection:
- Gut check:
- Development: http://localhost:8000
- Test: http://localhost:4000
- All endpoints should work for either port
- Auth
-
http://localhost:8000/v1/auth/signup
- a
201
will add an auth token to the headers
- a
-
request body:
{
"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
}
- http://localhost:8000/v1/auth/signin
- request and response body is the same as
/signup
- request and response body is the same as
- 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 in201
and logging info if you are logged in
Database connections with Prisma can be a little tricky as you have to connect to the database via the Docker container.
- 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
- 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
- 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
- Google Auth support
/signout
endpoint- Support for prod/deployment
- CI/CD support
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!
Lori McCurry - lori.mccurry@gmail.com