This is the backend repository for the codemmunity website project. Being built with NodeJs Express and a MYSQL Database.
This branch contains the basic boilerplate for an ExpressJs/NodeJs environment. Here is how to set it up on your machine:
- Pull the most recent code by running
git pullin your terminal - Run the setup shell scripts for your operating system (.ps1 is powershell)
- Run
node app.jsto start the server - You can use
npm run devcommand for the server to update dynamically with file changes
Get Docker here
To build the image with Docker run:
docker build -t codemmunity_backend/codemmunity_backend .docker build - use docker to build
-t codemmunity_backend/codemmunity_backend - tag it <ImageName>/<ImageTag>
. - using the Dockerfile in the current directory
This will build it using environment variables in the .env file
To run the Docker Image:
docker run -p 8080:8080 -t codemmunity/codemmunity_backend -ddocker run - run a docker image
-p 8080:8080 - expose port 8080 of the container to 8080 of your machine
-t codemmunity_backend/codemmunity_backend - with this name
-d - run container in background, detatch
To see your running docker containers run:
docker psTo stop a container run:
docker container stop <First 2 or more characters of the containerID>To remove a container run:
docker container rm <First 2 or more characters of the containerID>Get Docker Compose here
Ensure your environment variables are set in your .env file
To start MYSQL Container with docker-compose:
cd docker
docker-compose --env-file ../.env up -ddocker-compose [..] up - start the docker compose services
--env-file ../.env - use the environment variables from our .env file in the root directory
-d - detatch, run in the background
To stop MYSQL Container:
docker-compose --env-file ../.env downWARNING: The {VarName} variable is not set. Defaulting to a blank string.
If you see an error like this
Your .env file is not configured properly. Please make sure it matches the format in .env.example
Or
The path to your .env file is incorrect, ensure the .env file is in the project root directory, and you're running docker-compose from within docker folder.
clone the repository
git clone git@github.com:rohit0110/Codemmunity_Backend.gitthen enter the repo directory
cd Codemmunity_BackendPull any changes
git pullTo see the current status of your local repo run:
git statusThis will tell you any changes made that need to be added and committed.
Before you begin work on a new feature, create a new branch to work on:
git branch <Branch name>Then switch to that branch
git checkout <Branch name>To see the list of branches, and your current branch, run:
git branchOnce you have made your changes, add them to git
git add .And commit the changes:
git commit -m "Commit message"
The commit message should be short but also explain the changes.
Then push your changes to the branch on github
git pushThe first time you push a branch you will see an error with a command suggestion
fatal: The current branch github_docs has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin <branch name>
Copy the command and run it
To change back to the main branch run:
git checkout mainStash your changes
git stashThis will safely store your changes and revert to the last pull
Follow the steps to create a new branch.
Then to get your changes back run:
git stash pop