Socket
Book a DemoInstallSign in
Socket

@knovator/masters-node

Package Overview
Dependencies
Maintainers
0
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@knovator/masters-node

NodeJS backend for @knovator/masters

2.3.1
latest
Source
npmnpm
Version published
Maintainers
0
Created
Source

@knovator/masters-node

NodeJS package that integrate API for @knovator/masters-node in nodejs application
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

@knovator/masters-node is built with intent to faster development cycle by providing plug & play facility for masters/submasters, that is used almost on every project.

(back to top)

Built With

(back to top)

Getting Started

To integrate @knovator/masters-node, you should be having basic nodejs application up and running with express (optionally using mongoose for mongodb database). @knovator/masters-node add routes for masters in application.

Prerequisites

  • It's good start to have nodejs application up and running with express (optionally using mongoose for mongodb database). Good to have used i18next to add message in response codes.
  • routes uses mongoose connection established by application, so it's required to connect to database before using package. Example,
    // db.js
    const mongoose = require('mongoose');
    
    mongoose
      .connect('mongodb://localhost:27017/knovator')
      .then(() => console.info('Database connected'))
      .catch((err) => {
        console.error('DB Error', err);
      });
    
    module.exports = mongoose;
    
  • Image upload route for upload & remove is needed to declare externally. Example,
    // fileRoute.js
    const express = require('express');
    const router = express.Router();
    
    router.post(`/files/upload`, (req, res) => {
        // TO DO: some file storage operation
        let uri = "/image.jpg";
        let id = "62c54b15524b6b59d2313c02";
        res.json({
          code: 'SUCCESS',
          data: { id, uri },
          message: 'File uploaded successfully'
        });
    });
    
    router.delete(`/files/remove/:id`, (req, res) => {
        // TO DO: some file remove operation
        res.json({
            code: 'SUCCESS',
            data: {},
            message: 'File removed successfully'
        })
    })
    
    module.exports = router;
    

Sample App file

  require('./src/db');
  require('./src/models/file');

  const cors = require('cors');
  const express = require("express");
  const fileRoutes = require('./fileRoute.js');
  const PORT = 8080;

  const app = express();
  app.use(cors());
  app.use(express.static("public"));
  app.use(fileRoutes);

  // ...
  app.listen(PORT, () => {
      console.log(`App started on ${PORT}`);
  });

Installation

  • Install library
    npm install @knovator/masters-node
    # or
    yarn add @knovator/masters-node
    

(back to top)

Usage

App/Main file is a good place to use @knovator/masters-node

  ...
  const { masters } = require('masters-node');
  
  // ...
  app.use("/admin/masters", masters());
  app.listen(PORT, () => {
      console.log(`App started on ${PORT}`);
  });

Masters package allows providing authentication, logger and catchAsync functions as parameters.

app.use("/admin/masters", masters({
  authentication: (req, res, next) => {...},
  logger: console,
  catchAsync: (function) => (req, res, next) => {...}
}));

parameter explanations

  • authentication
    • Provides ability to add authentication to routes
      // default
      (_req, _res, next) => {
        return next();
      }
      
  • logger
    • Provides ability to add logging for Database and Validation
      // default
      console
      
  • catchAsync
    • Wraps functions to handle async errors
      // default
      function catchAsync(fn) {
        return function (req, res, next) {
          Promise.resolve(fn(req, res, next)).catch((err) => {
            // this.logger.error(err.message);
            res.status(internalServerError).json({
              code: RESPONSE_CODE.ERROR,
              message: err.message,
              data: {},
            });
          });
        };
      }
      

Routes Infomration

Response follows following structure

{
  code: RESPONSE_CODES,
  message: "" // if internationalized is applied
  data: {}
}

Response Codes

CodeDescription
SUCCESSWhen request fullfiled without error
ERRORWhen request fullfiled with error

Custom Validation messages

MessageDescription
Master existsWhen master/submaster with same code is exist in database

HTTP Status Codes

HTTPDescription
200When request fullfiled without error
201When document is created
500When internal server occurred
422When Validation error occurred

Routes

RouteDescription
/createCreates Master/SubMaster record
/update:idUpdates Master/SubMaster record
/partial-update/activate/:idTurn on/off isActive field based on body data
/partial-update/default/:idTurn on/off isDefault field based on body data
/partial-update/web-visible/:idTurn on/off isWebVisible field based on body data
/partial-update/sequence/:idSets sequence of record with :id, and updates affected records sequence
/deleteDelete the record whose id send in body

i18n code for messages

Nextjs i18n package adds facility for internationalization in nodejs application, and it's used in following mannerr

// usage
req?.i18n?.(CODE)
CODEDescription
(master/submaster).createWhen record is created
(master/submaster).updateWhen record is updated
(master/submaster).activateWhen isActive is set to true
(master/submaster).deactivateWhen isActive is set to false
(master/submaster).displayWhen isWebVisible is set to true
(master/submaster).notDisplayWhen isWebVisible is set to false
(master/submaster).defaultWhen isDefault is set to true
(master/submaster).notDefaultWhen isDefault is set to false
submaster.seqWhen sequence is updated
(master/submaster).deleteWhen delete is performed
(master/submaster).findAllWhen all data is fetched
(master/submaster).notFoundWhen Master/Submaster data is not found

descriptor codes

CodeDescription
master.createFor Create API
master.updateFor Update API
master.activeFor isActive toggle API
master.defaultFor isDefault toggle API
master.webVisibleFor isWebVisible toggle API
master.sequenceFor sequence update API
master.softDeleteFor Soft-Delete API
master.listFor List API
  • You can prefix descriptors by adding MASTERS_DESCRIPTOR_PREFIX in environment variables.

(back to top)

Usecases

@knovator/masters is combination of two packages @knovator/masters-admin and @knovator/masters-admin. It is designed plug and play masters module in your project. It is useful in following cases:

  • Your app needs master, submaster facility to build things like state with city, experiences with skills, categories with subcategories etc.
  • You want to let admin manage masters and submasters data from admin panel.
  • You want to show masters and submasters data somewhere in your app.

If you have any other usecase, please open an issue with tag usecase. We will try to add it in our roadmap.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  • Fork the Project
  • Create your Feature Branch (git checkout -b feature/AmazingFeature)
  • Commit your Changes (git commit -m 'Add some AmazingFeature')
  • Push to the Branch (git push origin feature/AmazingFeature)
  • Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Knovator Technologies

Project Link: https://github.com/knovator/masters-node

(back to top)

Keywords

masters

FAQs

Package last updated on 24 Jul 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.