This is a barebones API for node.js including the following features:
- Users and authentication
- Hashed/salted passwords
- User roles
- Routes for basic CRUD operations
- Routes for search operations
- Error logging
- Unit testing for individual functions
- Integration testing for routes
- node.js
- express
- postgresql
- sequelize
- jwt-simple (json-web-tokens)
- mocha
- chai
- chai-http
- proxyquire
Required installs:
- node.js
- postgresql
Once you have installed postgresql, open the terminal and create the database and user:
You will need to create a database called sample_api:
createdb sample_api
Next, start up psql and connect to the sample_api database:
psql sample_api
Create a user and grant access to sample_api database:
CREATE USER svc_sampleapi_dev WITH PASSWORD 'P6zIAwuvuNWo';
GRANT ALL PRIVILEGES ON DATABASE "sample_api" to svc_sampleapi_dev;
You should now be able to run npm install and then npm start. Sequelize will produce all of your database tables on startup.
All tests
npm test
From the terminal:
Unit tests only
npm run unitTest
Integration tests only
npm run integrationTest