Skip to content

voyager-index/server

Repository files navigation

A Node.js/Express powered server for all your mapping needs!

Quickstart

npm install    # install dependencies
source .env    # set environmental variables (optional)
npm run build  # build webpack bundle
npm run start  # start node server

Requirements

  • Node.js (runs the server).
  • PostgreSQL (runs the database).
  • Git (moves the code around).
  • pandoc (optional, converts views/pages/data_article.md to views/pages/data_article.ejs).
  • A shell and terminal (runs the code).

If you'd rather skip the pandoc installation, replace this line in nodemon.json:

    "restart": "node docs.js; sass public/stylesheets/main.scss public/stylesheets/main.css"

with:

    "restart": "sass public/stylesheets/main.scss public/stylesheets/main.css"

Server Setup

  • Get Source Code: git clone https://github.com/cs467-map/server

  • Install Node.js/npm: OS specific instructions.

  • Start Server:

# install dependencies
npm install

# set environment varibales
source .env

# build bundle
npm run build

# start server
npm run start

The server’s npm commands are defined in the package.json file:

"scripts": {
    "start": "nodemon -e js,ejs,json,scss,css,md index.js",
    "test": "node test.js",
    "dev": "webpack --config webpack.config.js --mode development",
    "watch": "webpack --config webpack.config.js --mode development --watch",
    "analyze": "webpack --config webpack.config.js --mode production --profile --json > stats.json",
    "build": "webpack --config webpack.config.js --mode production"
},

Browse to localhost:5000 and you should see the map!

example of server running on localhost

Heroku Setup

Setting up the Heroku workflow is only necessary if you wish to push changes to the production server at https://voyager-index.herokuapp.com/.

Requirements

Source:

https://devcenter.heroku.com/articles/getting-started-with-nodejs?singlepage=true

Install Heroku

See the section Note on Passwords below for a note on security.

# login to Heroku
heroku login

# if not already in the server directory, cd to it.
cd server

# set environmental variables.
source .env

# set database url for heroku host to use
heroku config:set DATABASE_URL=postgres://USER:PASSWORD@HOST/DATABASE

# add heroku remote
heroku git:remote -a $APP

# push to the heroku host
git push heroku master

Database Setup

Database installation and configuration instructions may be found at the database repo.

Note on Passwords

One of the commands above requires the password to interface with the hosted database.

heroku config:set DATABASE_URL=postgres://USER:PASSWORD@HOST/DATABASE

There are a few options available for inputting the password, each with different security levels and setup requirements:

Plain Input

Not very secure, as the password can be viewed as plain text and possibly stored in command history. But, it is fast and handy.

heroku config:set DATABASE_URL=postgres://coolUser:password123!@coolHost/coolDb

Export Environmental Variable

A little bit more secure, but the environmental variable may still may be viewed in command history, or by the operating system's superuser. See also.

export DB_PASS = 'password123!'
heroku config:set DATABASE_URL=postgres://coolUser:DB_PASS@coolHost/coolDb

Use a Password Manager

Much more secure, but requires some setup. Pass and KeepassXC are two Free, Open Source, and Cross Platform options.

pass init
pass add db
heroku config:set DATABASE_URL=postgres://coolUser:$(pass show db)@coolHost/coolDb