Lightweight PERN template with built-in Passport authentication.
This project is boilerplate code that has been built using a PERN stack (PostgreSQL, Express, React, Node) which includes Passport middleware and JWT for its authentication. The template has been written in Typescript, uses Material UI for its design system and Redux for its state management.
Library | Description |
---|---|
PostgreSQL | Relational database |
Express | Web application framework |
React | Component-based UI |
Node | Server-side JavaScript |
TypeScript | Typed superset of JavaScript |
Passport | Authentication middleware |
JWT | Access tokens |
BCrypt | Hash passwords |
Axios | HTTP client |
Redux | State management |
Material-UI | Design system |
Husky | Pre-commit hooks |
Prettier | Auto code formatting |
.
├── client #front-end
│ ├── src
│ │ ├── components #react components
│ │ ├── config #axios settings
│ │ ├── pages #page level components
│ │ ├── redux #state management
│ │ │ ├── actions #send data to redux store
│ │ │ └── reducers #respond to action state changes
│ │ └── utils #utilities
│ │ └── validation #validation utilities
│ └── public #html template
│
└── server #back-end
├── src
│ ├── config #db and passport settings
│ ├── controllers #interface between routes and db
│ ├── middleware #authorise protected requests
│ ├── models #db queries
│ └── routes #express api routes
└── .env #server config file
To get this project up and running, ensure the prerequisites have been met and then follow the installation steps below.
- Node
- NPM
- PostgresSQL
Once PostgreSQL has been installed, create a new database with a users
table:
CREATE DATABASE pern_template;
CREATE TABLE users (
user_id SERIAL PRIMARY KEY,
username VARCHAR UNIQUE NOT NULL,
password VARCHAR NOT NULL,
first_name VARCHAR NOT NULL,
last_name VARCHAR NOT NULL,
email VARCHAR UNIQUE NOT NULL
);
- Clone repository
git clone https://github.com/t-blackwell/pern-template.git
- Install node modules in root, client and server directories
npm install
- Add configuration file
.env
to server directory
NODE_ENV=development
PORT=5000
ACCESS_TOKEN_SECRET=secret_one
REFRESH_TOKEN_SECRET=secret_two
PGHOST=localhost
PGUSER=postgres
PGPASSWORD=password
PGDATABASE=pern_template
PGPORT=5432
- Reinitialise Git
rm -rf .git
git init
- Fire it up
npm run dev
Contributions to this project are welcome and appreciated.
- Fork the project
- Create your feature branch (
git checkout -b feature/NewFeature
) - Commit your changes (
git commit -m 'Add some NewFeature'
) - Push to the branch (
git push origin feature/NewFeature
) - Open a pull request
Distributed under the ISC License.
Any questions, suggestions or contribution ideas, please feel free to send me an email.
- Tom
This template was originally built using the pern-stack-typescript repo, special thanks to gandh99 for his help.