This is some boilerplate code for projects. This is a bare bones node/express app with basic local user authentication. It exists so that I don't have to start from scratch on my projects.
- Sequelize user model / migration
- Settings for PostgreSQL
- Passport and passport-local for authentication
- Sessions to keep user logged in between pages
- Flash messages for errors and successes
- Passwords that are hashed with BCrypt
- EJS Templating and EJS Layouts
Column Name | Data Type | Notes |
---|---|---|
id | Integer | Serial Primary Key |
createdAt | Date | Auto-generated |
updatedAt | Date | Auto-generated |
firstname | String | Must be provided |
lastname | String | - |
username | String | - |
String | Must be unique / used for login | |
password | String | Stored as a hash |
photoUrl | String | Profile Picture |
admin | Boolean | Defaults to false |
bio | Text | - |
birthday | Date | - |
Method | Path | Location | Purpose |
---|---|---|---|
GET | / | index.js | Home page |
GET | * | index.js | Render error/404 page |
GET | /auth/login | auth.js | Login form |
GET | /auth/signup | auth.js | Signup form |
POST | /auth/login | auth.js | Login user |
POST | /auth/signup | auth.js | Creates User |
GET | /auth/logout | auth.js | Removes session info |
GET | /profile | profile.js | Regular User Profile |
GET | /profile/admin | profile.js | Admin User Profile |
git clone <repo_link> <new_name>
npm install
(Or just npm i
for short)
Remove defaulty type stuff. Some areas to consider are:
- Title in
layout.ejs
- Logo in NavBar
- Description/Repo Link in
package.json
- Remove boilerplate's README content and replace with new project's readme
createdb <new_db_name>
- Change the database name
- Other settings are likely okay, but check username, password, and dialect
For example, if your project doesn't require a birthdate field, then don't keep that in there.
Delete from both the model and the migration.
sequelize db:migrate
- SESSION_SECRET: Can be any random string; usually a hash in production
Note: If using OAuth for Facebook and/or Github, switch to the directions on the
with-oauth
branch!!!
nodemon
or
node index.js
- Create a new repository on your personal Github account (via the GUI)
- Delete the old remote to origin (
git remote remove origin
) - Add the new repo link as a remote location you can push to (
git remote add origin <new_link>
) - Add, Commit, and Push
git add -A
git commit -m "Initial commit"
git push origin master
Note: Don't make commits from the new project to your auth boilerplate. Keep it PRISTINE for other future projects!