This example demonstrates how to use RethinkDB and JWT with an Express JS application. It is an API style application that is secured using JSON web tokens. When a user logs in, they are issued a token. The client then attaches the token to every request to gain access to the protected resources.
Make sure you have RethinkDB installed on your system by following the instructions found in the RethinkDB documentation.
In the root directory of the application create a hidden file called .env
and add the following information:
DB_HOST=localhost
DB_PORT=28015
DB_NAME=rethink_db
TOKEN_SECRET=mysupersecretstring
You will need to modify the above to your needs. If you need more information about how it works, please refer to the dotenv documentation and take particular note of the FAQ section.
Here is a list of npm modules I'm using:
express
- The application serverdotenv
- To configure the applicationbody-parser
- To parse JSONmorgan
- To log activitycors
- To allow requests from other domainshelmet
- For a bit of extra securityjwt-simple
- To issue access tokensmoment
- A date manipulation librarybcrypt
- To hash users passwordsexpress-rate-limit
- Setting limiter on routesxss-clean
- Data Sanitization against XSS attacksbluebird
- Bluebird is a fully featured promise library with focus on innovative features and performance- and of course
rethinkdb
- our database of choice!