Skip to content

vaibhavydv/node-mat-backend

Repository files navigation

Installation

  1. You need Node.js (at least 10.x version) installed on your machine, if you don't have it, you should install it - download link
  2. Clone the project from github or download the archive
  3. cd to your downloaded Argon app
  4. Install necessary dependencies:
    • Via node npm package manager - Run npm install on the project root
    • Via yarn package manager - Run yarn install on the project root

Configuration for PostgreSQL database and Redis data structure store

Via Docker
  1. Install Docker on your machine
  2. Run docker-compose up -d in a terminal on the project root. This will start 3 containers:
    • database(PostgreSQL) container;
    • redis container - required for session management;
    • haproxy container - required only for a staging/production setup;
Via another chosen solution.
  1. Install your PostgreSQL database
  2. Install your Redis server
  3. Change connection configuration, from your root cd to env-files folder and change the following configurations with your own:
For PostgreSQL connection:
  1. Database connection via URL
DATABASE_URL=http://creativeTim:creativeTim@127.0.0.1:5432/creativeTim
# Example: DATABASE_URL=http://<user>:<password>@<host>/<database_name>
  1. Database connection via credentials
DATABASE_HOST=127.0.0.1
DATABASE_PORT=5432
DATABASE_NAME=creativeTim
DATABASE_USER=creativeTim
DATABASE_PASSWORD=creativeTim
For Redis connection:
  1. REDIS connection via URL
REDIS_URL=redis://:@127.0.0.1:6379
# Example: redis://:<password>@<host>:<port>
  1. REDIS connection via credentials
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=

Migrations and seeds

  1. For database tables structure, in the project root run: npm run knex migrate:latest or yarn knex migrate:latest if you are using yarn as the default package manager
  2. To create a default user, run: npm run knex seed:run or yarn knex seed:run if you are using yarn as the default package manager

Run the application

  1. For starting the application, the following script (defined in package.json under scripts) must be called:
    • via npm: npm run start or npm run dev for starting the development environment, which has livereload enabled;
    • via yarn: yarn start or yarn dev for starting the development environment, which has livereload enabled;

Usage

Register a user or login using admin@argon.com:secret and start testing the preset (make sure to run the migrations and seeds for these credentials to be available).

Besides the dashboard and the auth pages this preset also has an edit profile page. NOTE: Keep in mind that all available features can be viewed once you login using the credentials provided above or by registering your own user.

Features

In order to see the available features cd into features folder, and you will then find a folder for each of the available features, mostly each folder containing:

  • A routes.js file that usually contains the GET and POST requests, for example, the profile router looks like this:
const { wrap } = require('async-middleware');

const requestBodyValidation = require('./commands/verify-request-body');
const updateUserInfo = require('./commands/update-user-info');
const { loadPage } = require('./commands/profile');

module.exports = (router, middlewares = []) => {
  router.get('/profile', middlewares.map(middleware => wrap(middleware)), wrap(loadPage));
  router.post('/update-profile-info', wrap(requestBodyValidation), wrap(updateUserInfo));

  return router;
};
  • A repository.js file that contains feature database queries
  • A commands folder where you can find all feature functionality functions, for example the login template rendering which looks like this:
function loadPage(req, res) {
  debug('login:loadPage', req, res);
  res.render('pages/login');
}
  • A constants.js file, to store all your static variables, for eg:
const USERNAME_PASSWORD_COMBINATION_ERROR = 'These credentials do not match our records.';
const INTERNAL_SERVER_ERROR = 'Something went wrong! Please try again.';

All feature routes are mounted in routes/index.js from the project root.# node-mat-backend

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published