Skip to content

altoinu/weather_map-server

Repository files navigation

weather_map-server

Detroit Labs coding challenge - simple weather forecast application - Backend Node.js server

This is a Node.js backend server to provide API to be used with weather forecast application altoinu/weather_map-client.

Writing README stuff

https://help.github.com/en/articles/basic-writing-and-formatting-syntax

Node stuff

Initial set up

npm install

Environment variables

Set following values via .env

# Array of origins to allow in CORS, JSON format
CORS_ALLOW_ORIGIN=["http://localhost", "http://localhost:3000"]
# Port number to listen to.
PORT=4000
# API key obtained from Open Weather Map
OPEN_WEATHER_MAP_API_KEY=XXXXXX

To run (for development)

npm run dev

...then try accessing one of defined routes:

To start/restart with PM2:

pm2 start [ecosystem config file].js
pm2 restart [ecosystem config file].js
pm2 startOrRestart [ecosystem config file].js
  • PM2 cluster mode
  • Immediately shuts down currently running process and then starts new one.
    • Causes this too-
      • App [app_name] with id [0] and pid [20743], exited with code [100] via signal [SIGINT]

To reload:

pm2 reload [ecosystem config file].js
pm2 startOrReload [ecosystem config file].js

To gracefully reload (RECOMMENDED):

pm2 gracefulReload [ecosystem config file].js
pm2 startOrGracefulReload [ecosystem config file].js (reloads env var as well)

Notes when restarting:

As of pm2 -v 3.5.1

  • --update-env option doesn't seem to be working as it should
  • watch: true does not update env that were changed in config .js/json
    • need to manually do pm2 startOrGracefulReload [ecosystem config file].js
  • Manual restart/reload/gracefulReload causes env to be updated to whatever is in config .js/json
    • However if env var is removed from .js/json, it still remains in process.env and gets loaded. Not sure if this is pm2/node bug or just the way things are. - To prevent this, do pm2 delete to completely remove then pm2 start

Lint

npm run lint:fix

Generating docs

npm run build:doc
  • Runs both apidoc and jsdoc

apidoc

npm run build:doc:apidoc

jsdoc

npm run build:doc:jsdoc

About

Detroit Labs coding challenge - simple weather forecast application. Backend Node.js server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors