npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medigo-server-kit

v0.1.10

Published

Server Kit for Medigo App

Readme

[MEDIGO] Server KIT

tested with jest jest


Getting started


Dependencies

Installation

install via NPM Package Manager

npm install medigo-server-kit

Features

  • Default Middleware
  • Router
  • Database (Mongoose, Sequelize)
  • Authentication And Authorization
  • Service Connection
  • Error And Handler

Usege

const ServerKit = require('medigo-server-kit')

const server = new ServerKit({
  name: 'Medigo Service Name',
  port: 8080
})

server.run()

Default Middleware Dependencies

This package comes with several middleware installed, but you can also add another middleware to the app. The default middlewares used are:

You can add middleware to the app with following:

...
const log = (req, res, next) => {
  console.log('hello middleware.')
  next()
}

server.middleware(log)

Or you can access directly to the express app

server.app.use(log)

Router

You can use express router express.Router as example below:

// router.js
module.exports = router => {
  router.get('/hello-medigo', (req, res, next) => {
    res.json({ message: 'hello too.' })
  })
  return router
}

// server.js
server.router(require('./router.js'))
server.run()

Database (Mongoose, Sequelize)

This package comes with Mongoose and Sequelize ORM. Both databases are using URI Connection in configuration.

const server = new ServerKit({
  name: 'Medigo Service Name',
  port: 8080,
  database: 'mongoose',
  connection: 'mongodb://{username}:{password}@localhost:27017/{name}'
})

// We recommend to setup database first before running the server
server.setUpDatabase().then(() => {
  server.run()
})

Both database ORM should use our db instance

- Mongoose

// user.js model of user
const mongoose = require('medigo-server-kit/database/mongoose').db
const Schema = require('medigo-server-kit/database/MongooseSchema')

// When using our schema, it will add timestamp, transform _id to id,
// and force _id field type to string instead of ObjectId
let userSchema = new Schema({
  username: { type: String, required: true },
  password: { type: String, required: true }
})

let UserModel = mongoose.model('User', userSchema)

UserModel.find({})

- Sequelize

If the service uses sequelize, you should install sequelize via npm to the app, because currently we don't provide schema for sequelize (will be provided later) and using this is still complicated. We will also update this documentation later.


Authentication And Authorization

This feature is currently under development, for a while, we provide simple Authorization like below:

const c = require('controllers')
const authorize = require('medigo-server-kit/security/authorize')

module.exports = router => {
  router.get('/doctor', authorize('adminGroupHC', 'adminHC'), c.doctor.getListDoctor)
  return router
}

Service Connection

To connect to another service around medigo services, this package also provide client connector for request. The service connectors available are:

  • Auth
  • User
  • HealthCenter
  • Doctor
  • SuperAdmin
  • Reservation
  • Schedule
  • Payment
  • Notification
  • Location
  • Storage
  • Middleware
  • MasterData

- Service Client

Example of usage

...
const UserService = require('medigo-server-kit/services/User')

async getUserList (req, res, next) {
  // req param is important to know where the request comes from,
  // who is the requesting user, and many more.
  let userClient = new UserService(req)
  let data = await userClient.get('/user')
  res.json(data)
}
...

- Service Connection

You can get access to current state of the request (such as authenticated user, healthCenter of the user, medigo-client and more by using Connection Class, Available informations are:

  • getClient object of id and name of medigo-client
  • getClientId x-medigo-client-id
  • getServiceName which service that is requesting
  • getClientName x-medigo-client-name
  • getUser object of current authenticated user
  • getHealthCenter current healthcenter of user
  • getUserId x-medigo-user-id
  • getHealthCenterId x-medigo-healthcenter-id

Example of usage

const ServiceConnection = require('medigo-server-kit/services/Connection')

module.exports = {
  getCurrentUser (req, res, next) {
    let SC = new ServiceConnection(req)
    // will return null if not exists
    res.json({ data: SC.getUser() })
  }
}

Error and Handler

We also provide error Classes that are automatically handled by the app.

  • Http
  • Server
  • Service
  • BadRequest
  • Forbidden
  • NotFound
  • Unauthentication
  • Validation
  • Validations

Example of usage

const Error = require('medigo-server-kit/error')

async getUserList (req, res, next) {
  try {
    if (false) {
      throw new Error.BadRequest('Something\'s wrong in your request.')
    }
  } catch (error) {
    next(error) // important to next for error handler
  }
}

Testing Directory

  • tests - Contains all the application tests
  • tests/__mocks__ - Subdirectory for mocks module are defined immediately adjacent to the module
  • tests/__tests__ - Contains all the scenario tests

Testing Application

Available tests command:

npm run test