WORK IN PROGRESS - DO NOT USE
The purpose of this project is to provide a starter kit for new product prototypes based on Nodejs that require a REST Api and websockets.
- User Accounts
- Roles
- ACLs
- Token based authentication using JWT
- Postgres drivers (to be refactored out into a pluggable alternative with thorough documentation on using different backends, no magic ORMs though)
- Database access patterns
- Websockets
- Production ready process manager
Tech | Description |
---|---|
Express | |
Knex | SQL query builder |
PassportJs | SQL query builder |
Babel | Transpiles javascript for both client and server |
Webpack | Used to build client side code |
ESLint | |
pm2 | Process manager |
npm Scripts | |
knexjs | query builder |
bookshelfjs | ORM built on knexjs |
- git clone reponame
- npm install
- Install and create database (postgres)
All node packages can be installed witn $ npm install
. The individual installations are listed
separately for reference:
$ npm install express --save
$ npm install passport --save
$ npm install morgan --save # Log requests to console
$ npm install body-parser --save # Extract params from POST requests
$ npm install jsonwebtoken --save # Create and verify JSON web tokens
$ npm install pm2@latest -g
$ npm install bcryptjs --save
$ npm install pg --save # postgres client [pg github](https://github.com/brianc/node-postgres)
$ npm install knex --save # or -g to have $ knex
$ npm install bookshelf --save
$ npm install lodash --save
$ npm install bluebird --save
$ brew update
$ brew install postgresql
$ which psql # confirm proper installation at /usr/local/bin/psql
$ postgres -D /usr/local/var/postgres # start postgres (some guides suggest starting with launchctl at startup, I prefer explicitly starting)
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start # alternative way to start mannually
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast # Stop manually
$ createdb `whoami` # create a default db based on your username
$ psql # logs into postgres shell
=# CREATE DATABASE your_db_name OWNER your_db_user ENCODING 'UTF8'
=# \d+ tablename
=# alter table.public.ingredients drop constraint ingredients_recipe_id_foreign, add constraint ingredients_recipe_id_foreign foreign key (recipe_id) references recipes(id) on delete cascade;
Script | ** Description ** |
---|---|
build | |
start | |
test | |
clean | |
startdb | Start postgres for local development |
migrate | creates database tables based on Schema.js |
webpack | webpack --progress --colors --watch |
I recommend using Postman to query you api during testing.
$ pm2 start app.js # Fork mode
$ pm2 start app.js -i 0 # Will start maximum processes with LB depending on available CPUs
$ pm2 list # Display all processes status
$ pm2 start app.js --watch
Should only be initialized one in the application as it creates a connection pool.
$ knex migrate:make migration_name
$ knex migrate:latest --env production
$ knex migrate:rollback
$ knex seed:make seed_name
$ npm install knex -g # install globally to run knex cli
$ knex seed:run
- need to install webpack globally
npm install webpack -g