Git Product home page Git Product logo

nodejs-api-starter-kit's Introduction

A Starter Kit for a Nodejs Web Server with a REST Api

Status

WORK IN PROGRESS - DO NOT USE

REPLACE THIS README WITH YOUR PROJECT SPECIFIC INFO

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.

Features

  • 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

Technologies used

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

Setup

  1. git clone reponame
  2. npm install
  3. Install and create database (postgres)

Install npm packages

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

Setup Postgres Database

Mac OS X
$ 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;
AWS

NPM Script Utilities

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

PM2 Process Manager

PM2 website

API Testing

I recommend using Postman to query you api during testing.

Token based Auth

pm2 commands

pm2 quickstart

$ 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

Bookshelfjs

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

Auth / Auth

Webpack

  • need to install webpack globally npm install webpack -g

nodejs-api-starter-kit's People

Contributors

stephenjjones avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.