Tosu app backend made with Node.js
- Clone the repository
git clone [email protected]:partio-scout/tosu-backend-node.git
- Install npm packages
npm install
- Add
.env
file to project root
NODE_ENV=development
HOST_URL=
SAML_METADATA_URL=
DB_HOST=localhost
DB_USERNAME=postgres
DB_PASSWORD=
DB_NAME_DEV=tosudb
DB_NAME_TEST=tosudb_test
DB_NAME_PROD=tosudb_prod
SECRET_KEY=superSecretKeyABC
NODE_ENV
defines the type of environment(production | development | test)
(development
by default)SECRET_KEY
is used for cookies.HOST_URL
is used for SAML routes (can be left undefined for local development).SAML_METADATA_URL
is used for fetching the SAML metadata for the IdP.
- Install postgreSQL (guide)
- Configure database credentials in
.env
if necessary - Create local development database
npx sequelize db:create
NOTE: If the above command doesn't work create the database manually
- Access SQL prompt using one of the following
$ psql $ psql -u postgres $ sudo -i -u postgres psql
- Create databases
-- For development CREATE DATABASE tosudb; -- For running tests CREATE DATABASE tosudb_test;
- Exit SQL prompt:
\q
orexit
-
Migrate models to the database
npx sequelize db:migrate
To undo migrations
npx sequelize db:migrate:undo:all
-
Start the server (2 options)
- Normal mode:
npm start
- Hot reloading:
npm run watch
- Normal mode:
- Run all tests
npm test
- Run single test class
npm test activities
Code coverage is generated when tests are run.
A report is printed to the console and an html report generated to /coverage.
- Get the unencrypted ssh key
tosu_node.pem
- SSH to the server instance:
$ chmod 600 tosu_node.pem
$ ssh-add tosu_node.pem
$ ssh [email protected]
- Install node:
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
$ sudo apt -y install nodejs
- Clone the repo:
$ git clone [email protected]:partio-scout/tosu-backend-node.git
- Add
.env
file to project root
NODE_ENV=production
HOST_URL=https://suunnittelu.beta.partio-ohjelma.fi
SAML_METADATA_URL=https://partioid-test.partio.fi/simplesaml/saml2/idp/metadata.php
DB_HOST=localhost
DB_USERNAME=postgres
DB_PASSWORD=(password for the database)
DB_NAME_DEV=tosudb
DB_NAME_TEST=tosudb_test
DB_NAME_PROD=tosudb_prod
SECRET_KEY=(generate some secret key)
- Install PM2, a process manager for Node.js applications:
$ sudo npm install pm2@latest -g
- Start node process:
$ cd ~/tosu-backend-node
$ npm install
$ pm2 start index.js
-
Install postgreSQL (guide)
-
Install NGINX, Reverse proxy and copy nginx.conf file:
$ sudo apt -y install nginx
$ sudo cp /home/ubuntu/tosu-backend-node/nginx.conf /etc/nginx/sites-available/default
- Restart nginx:
sudo systemctl restart nginx
TODO: Add documentation
Some documentation can be found in the doc
folder.
Product backlog (Trello)
Fall 2018 product & sprint backlog
This project is licensed under the MIT License - see the LICENSE file for details.