nodepress
TypeScript icon, indicating that this package has built-in type declarations

2.1.0-beta • Public • Published

NodePress

NodePress is a lightweight blog engine for node.js. At its current state it is useful as a compact library or boilerplate for a modular and extendible blog engine.

NodePress' web server is built on top of node-router. What is added on top of the server is a plugin functionality which renders one, or multiple, pair or individual set of client and server endpoints. Client endpoints being react components. This can be seen in any of the core plugin implementations, on /src/plugins.

Plugin system

NodePress relies on a plugin system to function. A plugin is an object that indexes frontend (React components) and backend (Fastify routes) endpoints to be served via the server. For that reason, NodePress allows for easily extendible and naturally modular projects.

Blog engine

By default, NodePress contains five plugins which make up a simple blog engine that renders markdown and latex math equations (using marked and katex). Those plugins are reader, feed, fetch, post, and user. You can take a look at the source of those plugins here. The user plugin contains essential user authorisation and management, while the other four make up the blog engine. It is possible to ignore all those plugins by initialising NodePress with the boolean ignoreCorePlugins. If you ignore core plugins, you can still manually load one or many of them, such as if you wish to use the user plugin but not provide a blog.

Initialisation example

const NodePress = require('NodePress');
const path = require('path');
 
const isDevEnv = process.argv.includes('--dev');
const args = {
    // Make config.json and set it up with an actual MongoDB URI.
    config: path.resolve(__dirname, 'config.json'),
    // Path to body and head HTML files.
    layout: {
        body: path.resolve(__dirname, 'layout/body.html'),
        head: path.resolve(__dirname, 'layout/head.html')
    },
    // Do not add any plugins to this example...
    plugins: [],
    //...but do not ignore core plugins.
    ignoreCorePlugins: false,
    // If dev environment, run on HTTP instead of HTTPS.
    dev: isDevEnv
};
 
// Start instance.
const instance = new NodePress(args);

Config.json example

{
    "net": {
        "interface": {
            "ports": {
                "https": 8080
            },
            "https": {
                "cert": "./some/path/fullchain.pem",
                "key": "./some/path/privkey.pem"
            }
        }
    },
    "db": {
        "uri": "mongodb_uri"
    },
    "user": {
        "root": {
            "password": "root_user_password"
        },
        "secret": {
            "key": "some_secret_encryption_key"
        }
    },
    "api": {
        "np_epoch": 1550620800000
    }
}

Database

NodePress uses MongoDB for database and Mongoose as interface by default.

Post schema

The following is the default structure of a post object, as used by the core post, reader, fetch and feed plugins.

{
    _id: ObjectId
    title: string
    content: string
    metadata: {
        date: Date
        author: string
        ...
    }
}

License

MIT

Package Sidebar

Install

npm i nodepress

Weekly Downloads

0

Version

2.1.0-beta

License

MIT

Unpacked Size

2.51 MB

Total Files

118

Last publish

Collaborators

  • rellfy