Giter Club home page Giter Club logo

kamla-bhasin's Introduction

Chanakya

How to run the Project?

  1. Ensure you are using Node version v10.16.0
  2. npm install to install the dependencies
  3. Set up the DB in POSTGRESQL. Read the How to use Knex Migrations? section.
  4. Create a .env file in the root directory of the project and update the required variables. You can use sample.env as the skeleton.
  5. npm start to run the server. The server will run with auto reloading using nodemon.

Good Practices

Linting

Code should be properly linted before any pull request is merged into the master. npm run lint to see all the linting errors. In cases where exceptions need to be made and a particular linting error cannot be fixed use the following code above the concerned line.

// eslint-disable-next-line no-useless-escape

Here no-useless-escape is the rule which needs to be ignored for the line below.

Constants

Don't hard code any values in the code whatsoever. Try to always declare the values in lib/constants.js instead of declaring them anywhere in the code. Here's an example on how we declared the current mode in constants and then used it across the code.

{
  mode: process.env.NODE_ENV,
  supportedModes: {
    prod: 'production',
    dev: 'development',
  },
}

The above snippet is from lib/constants.js. Now to write a conditional logic on basis of the mode which the server is running under right now, we wrote the following code in lib/services/exotel.js

if (CONSTANTS.mode !== CONSTANTS.supportedModes.prod) {
  // do something here
}

The mode is not picked from the process.env neither is the value to which it is compared.

Services

All the heavy business logic should exist strictly in the concerned services. No logic should be there in any helper file or the API endpoints

How to use Knex Migrations?

The initial schema created while developing Chanakya is not created as a Knex migration but stored in a SQL file in sqlScripts/initialSchema.sql. When you are installing Chanakya for the first time you need to first import this schema into the POTGTRESQL DB.

After importing the schema you can run the migrations using npm run knex migrate:latest.

Note: Check Import Schema section under Important Commands to see how to import the initialSchema.sql file into your DB.

Important Commands

Export Schema of DB

mysqldump -u root -p --no-data chanakya > schema.sql

Import Schema

mysql -u <insert your username> -p chanakya < sqlScripts/initialSchema.sql

Run server with Auto Reload

npm start

kamla-bhasin's People

Contributors

rohit1999-dev avatar abhishekgupta92 avatar prakash-simhandri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.