-
Install node.js and PostgreSQL
-
Clone repo then install packages using the command
npm install
-
Using PostgreSQL, Create DB for NB with a user that has full access to it. Helpful resource.
-
Add a config file for your database called config.js in the base folder of the project structured like below. Entries in config db should match the ones you used in Postgres:
var config = {
db: {
name: 'YOUR_DB_NAME',
user: 'YOUR_DB_USERNAME',
pass: 'YOUR_DB_PASSWORD'
}
}
module.exports = config;
- Add an
email-config.js
file in the base folder of the project (where config.js is) like below (you can use your gmail account or ask admin for test account):
const nodemailer = require("nodemailer");
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'EMAIL_ADDRESS',
pass: 'EMAIL_PASSWORD'
}
});
module.exports = transporter;
- Create a .env file with the following content and place it in the base folder of the project (where config.js is).
JWT_SECRET=ENTER-SECRET-HERE-(RANDOM-STRING)
- NOTE: Do not give the file a name (ie local.env), leave it as '.env'
- If you are on Mac you won’t be able to do this at first because ‘.’ files are hidden and therefore inaccessible/unwriteable by default. You need to run the following two lines in your command line tool first (to modify your hidden files temporarily), and when done run the same two lines but change the bool tag to a NO (to protect your hidden files):
defaults write com.apple.finder AppleShowAllFiles -bool YES
killall Finder
- If you are on Mac you won’t be able to do this at first because ‘.’ files are hidden and therefore inaccessible/unwriteable by default. You need to run the following two lines in your command line tool first (to modify your hidden files temporarily), and when done run the same two lines but change the bool tag to a NO (to protect your hidden files):
-
Run NB in separate terminals
- Run backend using command
npm run dev
- Run UI using command
npm run serve
- The UI has several errors listed in the command line when you run it, but it still works if you open up the server on your browser.
- Run backend using command
-
Access UI on https://127.0.0.1:8080/
- Note: Since we're using a self generated certificate for development, the browser will alert that you are running an insecure server. In Chrome type: thisisunsafe. (note: there is no text box to type this in, you have to type it on yout keyboard to get through). You can also press the advanced button then press continue to site.
-
SSH to the server
ssh -i [YOUR_KEY].key [USER]@[HOST].csail.mit.edu
-
Install NodeJS
curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash - sudo apt-get install -y nodejs
Helpful resource. -
Install PM2
sudo npm install -g pm2
Helpful resource. -
Follow steps 1 & 2 from Local Dev (see above).
-
Configure HTTPS on the server:
- Install certbot
$ sudo add-apt-repository ppa:certbot/certbot $ sudo apt-get update $ sudo apt-get install certbot
- Generate an SSL certificate with certbot
$ sudo certbot certonly --manual
- Part of the certbot configuration, type your domain name without the protocol part. For instance: yourname-nb.csail.mit.edu.
- When asked "Are you ok with your IP being logged?", type Y then ENTER.
- Open a new connection to the server on a new terminal, don't close the previous one.
- In the new terminal, navigate to the nb projecat and inside the public folder create a folder and name it
.well-known
, inside .well-know create another folder and name itacme-challenge
. - In the directory acme-challenge, create an empty file and name it as instructed from the certbot in the first terminal.
- Paste the challenge from the certbot into the file created in the previous step.
- Run the nb server using
sudo npm run http
, and verify that you can access the challenge on the URLhttp://[yourname]-nb.csail.mit.edu/.well-known/acme-challenge/[challenge file name]
- If everything is okay, go back to the first terminal and type ENTER.
- Finally, you will find all the files that you need under this path
/etc/letsencrypt/live/[yourname]-nb.csail.mit.edu
- Create .env file with the following content
SSL_KEY=PATH_TO/privkey.pem
SSL_CERT=PATH_TO/cert.pem
SSL_CA=PATH_TO/chain.pem
PORT=443
JWT_SECRET=ENTER-SECRET-HERE-(RANDOM-STRING)
-
To generate UI bundle, run
npm run build
. -
If you are runing
npm v7
or above, runsudo chown root .
. -
To start NB, run the following command
sudo pm2 start npm --name "NB" --time -- start
. -
To make PM2 run automatically after reboot, run the following command
sudo pm2 startup
then runsudo pm2 save
. -
You should be able to access NB using
[HOST].csail.mit.edu
. -
Redirect HTTP to HTTPS as follow
- run
sudo apt install nginx
. - run
sudo ufw allow 'Nginx HTTP'
. - edit
/etc/nginx/sites-enabled/default
and addreturn 301 https://$host$request_uri;
underserver_name
. - run
sudo systemctl reload nginx
.
sudo pm2 list # list all processes
sudo pm2 reload <ID|NAME|all> # reload after changes to the code
sudo pm2 del <ID|NAME> # delete process by id or name
sudo pm2 log < |NAME> # show log for all or by name
sudo pm2 log all # show all logs
to update certificate, run sudo certbot renew
, if this doesn't work try certbot certonly --manual -d $DOMAIN.com
then recreate the challange.