Coder Social home page Coder Social logo

orgtracker's Introduction

OrgTracker

A backend api service in node.js that serves two endpoints for an organization tracker.

Purpose

Provides a set of APIs that will allow us to track and search certain information for an organization.

Dependencies

  • Docker Download docker, from the official site (recommended) once is downloaded make sure the docker daemon is running.

  • Redis database - used for session/cache management (runs locally in docker)

  • Postgres database - used for storing orgs (runs locally in docker)

List of available endpoints

Path
get /health
post /api/v1/organization/new
post /api/v1/organization/search

*search requires the following JSON payload

{
    "orgname": "Test Org1"
}

*search requests are cached in redis for subsequent requests

curl http://localhost:9191/<endpoint>

Local development/Getting Started

Dependencies

Install Node (v12.4.0)

It's important that you use this version consistently to prevent package-lock.json churn.

Simple version: Download and install

NVM version:

  • Install NVM Install instructions.
  • Open a terminal into the root directory of the project
  • Install the version of node and use it with nvm install & nvm use.
  • Verify the version matches the version in the .nvmrc file with node --v.
  • You can set the Default version to use globally with nvm alias default <version>.

Local Environment Variables

Create a .env file to store local environment variables - this is used dotenv

DATABASE_URL='postgres://postgres:docker@localhost:5432'
PORT=9191
ORGTRACKER_APP_SECRET=9sb9g178-0701-4f01-b49e-2ed4854f77cd
REDIS_URL='redis://localhost:6379'
NODE_ENV=local

Project Layout

The project is laid out in the following way:

  • src: Project root
    • api: Routes, controllers and services (versioned routes)
    • config: Any required configuration variables
    • lib: Helper libraries
      • models: Sequelize data models
    • middleware: Connect-style express middleware
  • test: Jest/Supertest tests
  • scripts: Local utilities i.e. docker container management

Postgres Database

-- Table: public.organizations

-- DROP TABLE public.organizations;

CREATE TABLE public.organizations
(
    id integer NOT NULL DEFAULT nextval('organizations_id_seq'::regclass),
    orgname character varying(255) COLLATE pg_catalog."default" NOT NULL,
    "startDate" timestamp with time zone NOT NULL,
    "numberOfEmployees" integer NOT NULL,
    "isPublic" boolean NOT NULL DEFAULT false,
    "createdAt" timestamp with time zone NOT NULL,
    "updatedAt" timestamp with time zone NOT NULL,
    CONSTRAINT organizations_pkey PRIMARY KEY (id),
    CONSTRAINT organizations_orgname_key UNIQUE (orgname)

)

TABLESPACE pg_default;

ALTER TABLE public.organizations
    OWNER to postgres;

Installing and running

  1. Install
npm install
npm run local (runs redis and postgres database via docker (start and stop using redis_start and redis_stop scripts))

Tooling

  • Nodemon - auto-restarts modified javascript files in local development (install it globally)
  • Jest/SuperTest for testing API endpoints
  • Linting (eslint and prettier) - npm run lint - linting is also ran automatically is pre-commit hook (lint-staged)
  • Redis commander - GUI for viewing local redis instance data (optional)

Deployment

Project is running on Heroku at https://orgtracker.herokuapp.com/

orgtracker's People

Watchers

James Cloos avatar Fritz G. Batroni avatar  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.