A web app for planning and tracking an ideal day
This is a Node.js Express application that uses MongoDb for persistence and Angular for the client. The following dependencies will need to be installed for local development:
-
Node.js (Version 14 is ideal)
-
The Angular CLI (Version 11)
-
Typescript (Version 4)
-
Concurrently (an npm tool for running different Node.js processes simultaneously)
-
Docker Desktop. As well as testing container settings, we can run the MondoDb database through a Docker container instead of going through a local installation.
-
MongoDb (optional)
An .env
file will need to be created at the root of the project with the following settings:
APP_SECRET=<a secret to sign the app's JSON web tokens. This can be any string. Protect this.>
GOOGLE_CLIENT_ID=<register the app in the Google Dev Console: https://console.developers.google.com/>
GOOGLE_CLIENT_SECRET=<get your Google secret. Protect this.>
BD_USER=<The application user for the database. DbOwner of the application database>
BD_PWD=<The application user password. Protect this.>
MONGO_INITDB_ROOT_USERNAME=<The root user for the MongoDb Docker container. The DB can only be accessed with this account>
MONGO_INITDB_ROOT_PWD<The root user password. Protect this.>
DB_NAME=<The app database. 'beautifulDay' by default>
In Angular, ./client.src.environments/environment.ts
will need the following values updated:
export const environment = {
googleClientId: '<Must match GOOGLE_CLIENT_ID in .env>',
googleSessionStorageKey: 'Can be anything. Used to identify the authentication token that gets returned from Google and saved in sessionStorage',
jwtKey: 'Can be anything. Used to identify the apps JSON web token that is saved to localStorage'
}
Note that these values are assumed to be insecure.
Note, to
The package.json
contains the following scripts for this project's dev tasks:
-
$ npm run clean
- Clean out the./dist
directory before transpiling the Typescript files. -
$ npm run clean:db
- Remove all MongoDb artifacts from the./data/db
directory. Note, this command will request to be run undersudo
if the files were created through Docker. -
$ npm run cp:www
- Copy the./bin/www
Express.js entry file to the output directory. This file is otherwise ignored in the regular Typescript compilation. -
$ npm run cp:mongo
- Copy the MongoDb init files to the output directory. These files are needed for bootstrapping the database through Docker. -
$ npm run dev
- Run the project with local configurations. This process will runng build --watch
for client-side scripts,tsc -p […config] --watch
for application files, then it will run Nodemon to watch and restart the Express.js application. Note, there's some code inapp.ts
to refresh the browser whenever client-side code is updated, but sometimes this can lead to wonky performance. Comment it out if it' giving you grief. -
$ npm run prod
- Runs the project as above, but with production configurations. -
$ npm run build:all
- Compile all source code and files to './dist' for direct deployment. -
$ npm run build:img
- compile all source code and files to './dist' for Docker container deployment. -
Use:
docker-compose -f docker-compose-dev-yml up --force-recreate
to run the MongoDb database in a Docker container. See the configuration section above for the required environment variables.