This is a Node.js / Express
project bootstrapped with create-prospark-app
.
First, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
The following log message should be displayed in console output:
2023-04-17 23:14:38 PM [info] : Server started at http://localhost:8080
Visit http://localhost:8080/api/user/data
in your browser just to confirm routes are configured and working properly. If all is working properly, you should get the below response on browser.
{
"errorStatus": false,
"code": "--user/fake-data",
"message": "user data fetched successfully",
"statusCode": 200,
"data": [
{
"name": "john doe",
"email": "[email protected]"
},
{
"name": "brain tracy",
"email": "[email protected]"
}
]
}
Create a .env file inside the root of your application and include the following content:
DATABASE_URL='postgresql://postgres:@localhost:5432/prospark-db'
NODE_ENV="development"
JWT_SECRET="sdcsdcdc32ry38y9dpnp23i3892te832tp9e23on"
CLOUDINARY_NAME="ssdcsdcs"
CLOUDINARY_API_KEY="sdcscsdsdc"
CLOUDINARY_API_SECRET="sdcdscsdcc"
Navigate to cloudinary to retrieve needed info for your .env
file.
Note!! you need to create the database
zuriportfolio
yourself before doing any other thing within the app if you need it to work properly. You could use tool likePhpMyAdmin
orMysqlWorkBench
drop schema public cascade;
create schema public;
The routes can be found within the /routes
directory. for eg the user route would handle routing that has to do with the user controllers which is prefix with /user/*
and when been invoked, would be done in this format /api/user/*
const express = require('express');
const UserController = require('../controller/user');
const useCatchErrors = require('../error/catchErrors');
class UserRoute {
router = express.Router();
userController = new UserController();
path = '/user';
constructor() {
this.initializeRoutes();
}
initializeRoutes() {
this.router.get(`${this.path}/data`, useCatchErrors(this.userController.getUser.bind(this.userController)));
}
}
module.exports = UserRoute;
Also, within each controller file, notice that try...catch
isn't been used, this is because I've created an error method
called useCatchErrors
which would handle all exceptions / error thrown within any controller file.
Do Not Touch the Base file within the controller directory. It should only be inherited from.
- dev -> pr this branch for everything
frontend
&backend
related - main -> dont touch this branch, this is what is running in production.
- Clone the repo
git clone https://github.com/hngx-org/zuriportfolio-commander-backend.git
. - Open your terminal & set the origin branch:
git remote add origin https://github.com/hngx-org/zuriportfolio-commander-backend.git
- Pull origin
git pull origin dev
- Create a new branch for the task you were assigned to, eg :
git checkout -b feat-csv-parser
- After making changes, do
git add .
- Commit your changes with a descriptive commit message :
git commit -m "your commit message"
. - To make sure there are no conflicts, run
git pull upstream dev
. - Push changes to your new branch, run
git push -u origin feat-csv-parser
. - Create a pull request to the
dev
branch notmain
. - Ensure to describe your pull request.
-
If you've added code that should be tested, add some test examples.
Type | Description | |
---|---|---|
feat | Features | A new feature |
fix | Bug Fixes | A bug fix |
docs | Documentation | Documentation only changes |
style | Styles | Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc) |
refactor | Code Refactoring | A code change that neither fixes a bug nor adds a feature |
perf | Performance Improvements | A code change that improves performance |
test | Tests | Adding missing tests or correcting existing tests |
build | Builds | Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm) |
ci | Continuous Integrations | Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs) |
chore | Chores | Other changes that don't modify backend, frontend or test files |
revert | Reverts | Reverts a previous commit |
Sample Commit Messages
chore: Updated README file
:=chore
is used because the commit didn't make any changes to the backend, frontend or test folders in any way.feat: Added plugin info endpoints
:=feat
is used here because the feature was non-existent before the commit.