Description coming soon ...
Use | Tech |
---|---|
Virtual Environment | Docker |
Language | TypeScript |
Backend Runtime | Node.js |
Backend Framework | Express.js |
SQL Database | Postgres |
Unit Tests | Mocha |
In order to properly set up this project on your computer you only need Docker Desktop, though it is recommended that you also have Node.js installed.
Download Docker: Docker.com
Docker Tutorial: FreeCodeCamp.org
Download Node.js: Nodejs.org
Node.js Tutorial: PluralSight.com
Once they are installed, run the following command in terminal to pull the code from GitHub:
git clone https://github.com/IkeHunter/Jukebox.git
Then navigate to that new folder (make sure you are in the project directory)
cd Jukebox
You will need to create the environment variables and any other private variables (secrets) the project uses, you can easily do so with this command which will walk you through the steps:
npm run config
This will create a .env file that contains the necessary environment variables for the server, database, and any other applications that are used. It also creates a new directory called /Playground
which is described below.
The next command builds the docker containers:
docker build .
After the docker containers are built, you simply need to run them with this command to activate the server and database:
docker-compose up
[... describe accessing localhost]
There are a host of commands built in to this project to make certain tasks easier and more streamlined. Since this project is contained within Docker, running the Node server and Test suite may not be the most intuitive, however. That and more is explained below.
The containers defined in docker-compose.yml run automatically with docker-compose, but this will attach the Node server to the API container - essentially making the container unable to run without Node running. To get around this you can either use docker instead of docker-compose, or just restart the docker container when you need to hard restart the server (it restarts automatically with nodemon).
In order to run tests with the docker-compose containers, you first need to access the container shell in a new terminal window with the following command:
Open Container Shell
docker exec -it api sh
After the container shell is opened, you are able to run tests on the active Node server. Node: the server must be running while tests are performing. To run the mocha
test suite, use the following command:
Run Unit Tests
npm test
Sometimes you may want to test a bit of code or a feature without effecting the main project, you can do so inside the /playground
directory created during configuration. This directory is hidden from git, so anything added to this folder will be excluded from commits, version control, and GitHub.
This directory contains a simple server.js
file that can be run using the following command:
Open Container Shell
npm run playground
Coming soon!
Helpful websites:
setup docker, node, postgres, typescript:
https://dev.to/chandrapantachhetri/docker-postgres-node-typescript-setup-47db
another getting started article: https://www.docker.com/blog/getting-started-with-docker-using-node-jspart-i/
docker best practices with node: https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/
start with mocha: https://semaphoreci.com/community/tutorials/getting-started-with-node-js-and-mocha
Test node api: https://www.digitalocean.com/community/tutorials/test-a-node-restful-api-with-mocha-and-chai
Beginner Resources:
Start node server: https://levelup.gitconnected.com/set-up-and-run-a-simple-node-server-project-38b403a3dc09
environment variables: https://itnext.io/how-to-use-environment-variables-in-node-js-cb2ef0e9574a