An Express.js API backend built to support the shopper React application.
This API was developed in Node 18.19.1. To avoid any version errors ensure yours is on this release or above
by using node -v
. If you are comfortable working on an older version you can go ahead and see all
requirements, and their version, in ./package.json
.
Once you have ensured your Node install is ready to use install all dependencies by running
npm i
Once all the dependencies are installed you need to configure the envionrment variables. Create the file ./config/.env
. The following configuration variables need to be set
EXPRESS_PORT=5000
ACCESS_TOKEN_DURATION=15
REFRESH_TOKEN_DURATION=7
SEQUELIZE_DIALECT='sqlite'
SEQUELIZE_DB_URI='sqlite://db/shopper.db'
SEQUELIZE_DB_PATH='/db/shopper.db'
DB_MODELS='/db/models'
SECRET_KEY='my secret key'
These are just default/dummy values I have included here. You are welcome to choose what you please.
Caution
If you ever deploy this application make sure the SECRET_KEY
is set to something secure. This can be done with the UUID node package or another method of your preference.
I have included all the up to date database migration files (generated with
Atlas) in ./db/migrations
. To initialise the database make sure
you have atlas
(this is not an npm
package so you will need to follow the installation instructions) installed and run atlas migrate apply --env sequelize
. This will create the sqlite
database ./db/shopper.db
.
Now use npm start
to start the application. It will run, by default, on localhost:5000
. You can optionally, change the port by using the EXPRESS_PORT=<port>
variable in ./config/.env
. Documentation of all endpoints can be found at localhost:<port>/
.
Note
This applciation is not configured for production. If you wish to serve this application please make sure you follow Express best practices.
The API uses several npm packages. I have listed the main ones here but for a complete list see
./package.json
.
Apologies if I have left someones' work out.