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

@open-stock/stock-universal-server

v4.2.310

Published

> TODO: description

Downloads

3,183

Readme

@open-stock/stock-univesal-server

A exposes universal functionality to all othet @open-stock libraries on the server side. This library requires @open-stock/stock-universal to be initialised first.

A bunch of helper functions

Sample code:

import {
  runStockUniversalServer,
  createDirectories,
} from "@open-stock/stock-universal-server";

const databaseConfigUrl = "";
await runStockUniversalServer(databaseConfigUrl);

Installation

// with npm
npm install @open-stock/stock-universal-server

// with yarn
yarn add @open-stock/stock-universal-server

How to use

import {
  runStockUniversalServer,
  createDirectories,
} from "@open-stock/stock-universal-server";

const databaseConfigUrl = ""; // must be a mongodb connection string
await runStockUniversalServer(databaseConfigUrl);

Extra Features

The following are the features of the stock-universal library

NOTE

Most of the features below are automatically implememnted by the library. But If you want to use the classes and functions provided by the library, you can do so by importing them from the library. Some of them are elaborated below.

getEnvVar

getEnvVar is a function that is used to get the environment variables from the process.env object. It is used by the EhttpController to get the environment variables

usage

import { getEnvVar } from "@open-stock/stock-universal-server";

const name = 'name'
const envVar = getEnvVar(name);

getExpressLocals

getExpressLocals is a function that is used to get the express locals from the express request object. It is used by the EhttpController to get the express locals

usage

import { getExpressLocals } from "@open-stock/stock-universal-server";
import express from 'express';
const app = epress();

const localVar = getExpressLocals(app, 'name');

apiRouter

apiRouter is a function that is used to get the express router for the api. It is used by the EhttpController to get the express router for the api

usage

import { apiRouter } from "@open-stock/stock-universal-server";
import express from 'express';
const app = epress();

app.use('/api', apiRouter());

requireAuth

requireAuth is a function that is used to get the express middleware for the authentication api. It is used by the EhttpController to get the express middleware for the api

usage

import { requireAuth } from "@open-stock/stock-universal-server";
import express from 'express';
import { authRouter } from './authRouter';

const app = epress();

app.use('/api', requireAuth(), authRouter());

makeUrId

makeUrId is a function that is used to mkake an id by incrementing the supplie value by 1.

usage

import { makeUrId } from "@open-stock/stock-universal-server";

const lastPosition = 11;
const id = makeUrId(lastPosition);

getHostname

getHostname is a function that is used to get the running hostname;

usage

import { getHostname } from "@open-stock/stock-universal-server";
import { apiRouter } from './apiRouter';
import express from 'express';

const app = epress();

app.use('/api', apiRouter());

apiRouter.get('/hostname', (req, res) => {
const hostname = getHostname(req);
});


// or without request object
const hostname = getHostname();

stringifyMongooseErr

stringifyMongooseErr is a function that is used to stringify the mongoose error object

usage

import { stringifyMongooseErr } from "@open-stock/stock-universal-server";

const errString = stringifyMongooseErr(err);

offsetLimitRelegator

offsetLimitRelegator is a function that is used to get the offset and limit from the request query.

usage

import { offsetLimitRelegator } from "@open-stock/stock-universal-server";

const initialOffset = 0;
const initialLimit = 10;

const { initialOffset, initialLimit } = offsetLimitRelegator(req);

verifyObjectId

verifyObjectId is a function that is used to verify if a string is a valid mongoose object id

usage

import { verifyObjectId } from "@open-stock/stock-universal-server";

const valid = verifyObjectId(id);

verifyObjectIds

verifyObjectIds is a function that is used to verify if an array of strings are valid mongoose object ids

usage

import { verifyObjectIds } from "@open-stock/stock-universal-server";

const valid = verifyObjectIds(ids);

createDirectories

createDirectories is a function that is used to create directories

usage

import { createDirectories } from "@open-stock/stock-universal-server";

const appName = 'app';
const absolutepath = '/'; // you might want to get this from process.cwd()
const directories = ['dir1', 'dir2', 'dir3'];

const created = await createDirectories(appName, absolutepath, directories);

checkDirectoryExists

checkDirectoryExists is a function that is used to check if a directory exists

usage

import { checkDirectoryExists } from "@open-stock/stock-universal-server";

const absolutepath = '/'; // you might want to get this from process.cwd()
const useAbsolutePath = 'first';

const exists = await checkDirectoryExists(absolutepath, useAbsolutePath, useAbsolutePath);

uploadFiles

uploadFiles is a middleware function that is used to upload files to a server

usage

import { uploadFiles } from "@open-stock/stock-universal-server";

appendBody

appendBody is a middleware function that is used to append the body to the request object after uploadFiles middleware

usage

import { appendBody } from "@open-stock/stock-universal-server";

saveMetaToDb

saveMetaToDb is a middleware function that is used to save the meta data to the database after appendBody middleware

usage

import { saveMetaToDb } from "@open-stock/stock-universal-server";

updateFiles

updateFiles is a middleware function that is used to update files

usage

import { updateFiles } from "@open-stock/stock-universal-server";

deleteFiles

deleteFiles is a middleware function that is used to delete files

usage

import { deleteFiles } from "@open-stock/stock-universal-server";

getOneFile

getOneFile is a middleware function that is used to get one file

usage

import { getOneFile } from "@open-stock/stock-universal-server";

returnLazyFn

returnLazyFn is a function that is used to return response status 200 okay after all middleware functions have been executed successfully

usage

import { returnLazyFn } from "@open-stock/stock-universal-server";

Documentation

The source code of the website can be found here. Contributions are welcome!

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.

License

MIT