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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mikrocms/core

v1.1.1

Published

Package core mikrocms

Downloads

179

Readme

The core of the mikrocms package is the module initialization system. It starts with loading the core on the index of the Express app and passing the configuration.

mikrocms core workflow

Default Module

The important thing about the mikrocms module is the default module. You must have one module named default. When other modules interact with the configuration without specifying the name of the module, they will refer to the default module configuration.

module.exports = {
  "modules": {
    "default": {
      "database": {},
      "schema": {},
      "model": {},
      "locale": {},
      "middleware": {},
      "router": {},
      "service": [],
      "public": {}
    }
  }
}

Configuration

Configuration includes environment settings and all the modules we have, and it is passed into the mikrocms initialization. The configuration can be stored in a separate file or included directly:

module.exports = {
  "env": {},
  "modules": {
    "module_name": {
      "database": {},
      "schema": {},
      "model": {},
      "locale": {},
      "view": [],
      "middleware": {},
      "router": {},
      "service": [],
      "public": {}
    }
  }
}

Environment Configuration

Shared data configuration involves managing and accessing configuration data across different parts of an application or across multiple modules. Environment variables are commonly used to store configuration data that needs to be shared.

"env": {
  // all environment variables
}

Database Configuration

Managing database connections efficiently is crucial for the performance and scalability of your application. The configuration file for mikrocms allows you to define multiple database connections in a centralized manner. The database used by mikrocms utilizes the Sequelize package. The database configuration references Sequelize:

"database": {
  "connection_name": {
    "database": "name_of_database",
    "username": "username_of_user",
    "password": "password_of_user",
    "sequelize": {
      "host": "hostname",
      "port": "port",
      "dialect": "mysql"
      // other Sequelize configurations
    }
  }
}

Schema Configuration

The schema configuration defines the structure of your database tables using Sequelize models. Each model represents a table in your database:

"schema": {
  "schema_name": {
    "connection": "name of the database connection",
    "structure": require("path_to_schema_file")
  }
}

Schema file:

function (sequelize) {
  return {
    attributes: {
      // defining the fields of the model
    },
    options: {
      tableName: "name_of_table",
      // other Sequelize schema options
    }
  };
}

Model Configuration

Models contain all methods callable by our service and other models to process queries to the database tables. We can also define schema relationships within the migration method.

"model": {
  "model_name": require("path_to_model_file")
}

Model file:

function ({ env, db, schema, model, lib }) {
  function migration() {
    // Define migrations here
  }

  return {
    migration,
    // other model methods
  };
}

Locale Configuration

Web localization is the process of adapting a website or web application to different languages and regions, making it suitable for users from various cultural backgrounds:

"locale": {
  "language_code": require("path_to_locale_file")
}

Locale file:

module.exports = {
  “locale_id”: “locale format string”
}

View Configuration

The view folder helps organize and separate the presentation layer from the business logic in your application.

view: [
  "path_to_your_view_directories"
]

Middleware Configuration

The middleware configuration defines methods to intercept requests.

"middleware": {
  "middleware_name": require("path_to_middleware_file")
}

Middleware file:

function ({ env, model, locale, middleware }) {
  return [
    // all handler methods
  ];
}

Router Configuration

Express Router is a built-in feature of the Express.js framework that allows you to create modular, mountable route handlers. It is a powerful tool for organizing your application’s routing logic, making your code more modular and easier to maintain.

"router": {
  "endpoint": [
    "middleware name" or ["module name", "middleware name"]
  ]
}

Service Configuration

In the context of Express.js, an Express handler is a function that processes HTTP requests and sends back a response. In mikrocms we refer to this as a service, which is used to manage incoming requests and control how the server responds.

"service": [
  {
    "router": "endpoint of router" or ["module name", "endpoint of router"],
    "handler": {
      "endpoint": {
        "HTTP Method": require("path_to_service_file")
      }
    }
  }
]

Service file:

function ({ env, model, locale, middleware }) {
  return [
    // all handler methods
  ];
}

Public Configuration

These files are directly accessible by the client (e.g., web browsers) without any server-side processing.

Configuration format:

"public": {
  "endpoint": {
    "middleware": [
      "middleware name" or ["module name", "middleware name"]
    ],
    "path": "path_to_your_public_directories"
  }
}

Read more documentation