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

nodejs-blog

v1.0.0-alpha.2

Published

A blog API built in NodeJS that can be used as a standalone application, or included in a NodeJS application

Downloads

23

Readme

NodeJS Blog API Project maintainers

Build Status codecov Known
Vulnerabilities npm version NodeJS Version GPLv3 license

Blog API developed by Bytecode Digital Agency as free (as in freedom) open source software. Built in NodeJS. Available as a standalone server, or as a NPM package

Installation

To install the module, run

yarn add nodejs-blog

or

npm install nodejs-blog

For contributing to the development, fork the GitHub repository.

Configuration

This part is not implemented in the code yet.

To use the NodeJS Blog module, first, import the package

const nodeBlog = require('nodejs-blog');
const { authors, auth, users, categories, articles } = require('nodejs-blog');

to start using the package, create a new blog object:

const client = 'YOUR_DB_CLIENT'; // for more info, see https://knexjs.org/
const host = 'YOUR_DB_HOST';
const database = 'YOUR_DB_NAME';
const user = 'YOUR_DB_USER';
const pass = 'YOUR_DB_PASS';
const debug = true || false;

const blog = nodeBlog(client, host, user, database, password, debug);

For authentication you should set the following environment (process.env.[variable] = value) variables, or the auth methods will not work:

SALT_ROUNDS=number
JWT_SECRET=string
JWT_EXPIRES_IN_DAYS=number_of_days

Then you can use the imported functions as you wish, for example:

const posts = await articles.list(blog);

Just send the blog instance as the first argument and the rest of the arguments second. This is because this way the same logic can be applied to multiple blog instances within an application.

The available methods are:

authors.list(blog)
authors.get(blog, id)
authors.add(blog, authorObject)
authors.modify(blog, id, modifiedData)
authors.delete(blog, id)

auth.authenticate(blog, username, password) // Returns true/false
auth.generateToken(blog, username, password) // Returns JWT, throws error if invalid credentials
auth.decode(jwt) // Returns decoded object
auth.validate(blog, username, password) // Returns true/false

users.list(blog)
users.get(blog, id)
users.add(blog, userObject)
users.modify(blog, id, modifiedData)
users.delete(blog, id)

categories.list(blog)
categories.get(blog, id)
categories.add(blog, categoryObject)
categories.modify(blog, id, modifiedData)
categories.delete(blog, id)

articles.list(blog)
articles.get(blog, id)
articles.add(blog, articleObject)
// articles.modify(blog, id, modifiedData) // not available yet
articles.delete(blog, id)

We recommend creating a single file that will create the NodeBlog instance, and export this instance, and import in all other files where you want to use NodeJS Blog.

For security reasons we recommend using environment variables for loading the configuration. This is also in compliance with the 12 factor app Config guidelines.

Note: NodeJS blog was made to be used with PostgreSQL, but it should(/could) also be compatible with other databases, as it uses KnexJS under the hood.

A demo application and a standalone CLI are currently in development

Running the API as a standalone service (still in development, might not work 100%)

First clone the repository and cd into the directory.

To run NodeJS Blog as a standalone service, run cp .env.example .env to create the .env file.

Set your database details and preferences in the .env file and run yarn run start.

The API documentation can be generated using SwaggerUI. The contents can be found in ./swagger.yml.

For authentication, add a Authorization header, with a bearer token, following the Bearer [jwt-token] convention.

Development

For development, the following commands are available:

| Command | Functionality | | - | - | | yarn run dev | Runs a nodemon server for the server/server.js file, and exposing the standalone service to your localhost | | yarn run cli | Runs the CLI tool created for simple CRUD operations without accessing the database directly | | yarn run lint | Runs ESLint, for PRs this should always pass | | yarn run test | Runs Jest once, for PRs this should always pass. Your database must be available as it is used to run tests on (beware: all existing data will be wiped, we recommend using a separate test-database, this can be set in the .env file) | | yarn run test:watch | Same as yarn run test, but it Jest watches for changes | | yarn run coverage | Creates coverage report, for this the test database should also be available | | yarn run migrate | Migrates your database (normal one, not test database) to the most recent migration, seeds will not be ran | | yarn run reinstall | Deletes the node_modules/ folder and reinstalls everything, if you get some stange dependency errors, run this command | | yarn run clean | Deletes folders build/, dist/ and coverage/ |

Node Environments

The following NodeJS Environments are integrated:

| Env | Effect | | --- | ------ | | development | Will add development headers, and improve logging experience | | test | Will use test database, should only be used for automatic testing | | production | Production mode |