3.8.5 • Published 3 days ago

@open-stock/stock-universal-server v3.8.5

Weekly downloads
-
License
ISC
Repository
-
Last release
3 days ago

@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

3.7.5

4 days ago

3.7.4

4 days ago

3.7.3

4 days ago

3.7.9

3 days ago

3.7.8

3 days ago

3.7.7

4 days ago

3.7.6

4 days ago

3.8.0

3 days ago

3.8.4

3 days ago

3.8.3

3 days ago

3.8.2

3 days ago

3.8.1

3 days ago

3.8.5

3 days ago

3.7.2

7 days ago

3.6.9

8 days ago

3.7.1

8 days ago

3.7.0

8 days ago

3.6.8

8 days ago

3.6.7

9 days ago

3.6.6

10 days ago

3.6.5

10 days ago

3.6.4

12 days ago

3.6.3

15 days ago

3.6.2

17 days ago

3.6.1

17 days ago

3.6.0

17 days ago

3.5.7

17 days ago

3.5.6

17 days ago

3.5.9

17 days ago

3.5.8

17 days ago

3.5.3

18 days ago

3.5.2

18 days ago

3.5.1

18 days ago

3.5.0

18 days ago

3.5.5

18 days ago

3.5.4

18 days ago

3.4.4

18 days ago

3.4.3

18 days ago

3.4.2

18 days ago

3.4.1

18 days ago

3.4.8

18 days ago

3.4.7

18 days ago

3.4.6

18 days ago

3.4.5

18 days ago

3.4.9

18 days ago

3.3.9

22 days ago

3.3.8

22 days ago

3.3.7

22 days ago

3.2.6

22 days ago

3.2.8

22 days ago

3.2.7

22 days ago

3.4.0

22 days ago

3.3.1

22 days ago

3.3.0

22 days ago

3.3.5

22 days ago

3.3.4

22 days ago

3.3.3

22 days ago

3.3.2

22 days ago

3.2.4

24 days ago

3.2.2

28 days ago

3.2.3

28 days ago

3.2.1

29 days ago

3.2.0

29 days ago

3.1.3

29 days ago

3.1.2

29 days ago

3.1.1

29 days ago

3.1.0

29 days ago

3.1.7

29 days ago

3.1.6

29 days ago

3.1.5

29 days ago

3.1.4

29 days ago

3.1.9

29 days ago

3.1.8

29 days ago

3.0.4

29 days ago

3.0.8

29 days ago

3.0.7

29 days ago

3.0.6

29 days ago

3.0.9

29 days ago

3.0.3

30 days ago

2.8.1

1 month ago

2.8.0

1 month ago

3.0.2

1 month ago

3.0.1

1 month ago

2.9.2

1 month ago

2.7.4

1 month ago

2.9.1

1 month ago

2.7.3

1 month ago

2.9.4

1 month ago

2.9.3

1 month ago

2.7.5

1 month ago

3.0.0

1 month ago

2.9.6

1 month ago

2.7.8

1 month ago

2.9.5

1 month ago

2.7.7

1 month ago

2.9.0

1 month ago

2.7.2

1 month ago

2.7.1

1 month ago

2.8.3

1 month ago

2.8.2

1 month ago

2.8.5

1 month ago

2.8.4

1 month ago

2.8.7

1 month ago

2.8.6

1 month ago

2.8.9

1 month ago

2.8.8

1 month ago

2.7.0

1 month ago

2.6.9

1 month ago

2.6.8

1 month ago

2.6.7

1 month ago

2.6.6

1 month ago

2.6.1

2 months ago

2.6.3

2 months ago

2.6.2

2 months ago

2.6.5

2 months ago

2.6.4

2 months ago

2.6.0

2 months ago

2.5.8

2 months ago

2.5.7

2 months ago

2.5.9

2 months ago

2.5.6

2 months ago

2.5.5

2 months ago

2.5.0

2 months ago

2.5.2

2 months ago

2.5.1

2 months ago

2.5.4

2 months ago

2.5.3

2 months ago

2.4.8

5 months ago

2.4.1

5 months ago

2.4.3

5 months ago

2.4.2

5 months ago

2.4.5

5 months ago

2.4.4

5 months ago

2.4.7

5 months ago

2.4.6

5 months ago

2.4.0

5 months ago

2.3.2

6 months ago

2.3.6

6 months ago

2.3.5

6 months ago

2.3.7

6 months ago

2.3.1

6 months ago

2.3.0

6 months ago

2.1.2

7 months ago

2.0.3

8 months ago

2.0.2

8 months ago

2.0.4

8 months ago

2.2.5

6 months ago

2.0.7

8 months ago

2.2.4

6 months ago

2.0.6

8 months ago

2.0.8

8 months ago

2.1.0

8 months ago

2.0.1

8 months ago

2.0.0

10 months ago

2.2.9

6 months ago

2.2.8

6 months ago

1.4.5

11 months ago

1.3.4

11 months ago

1.4.0

11 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.2.7

11 months ago

1.2.6

11 months ago

1.2.5

11 months ago

1.2.4

11 months ago

1.2.3

11 months ago

1.1.4

12 months ago

1.1.3

12 months ago

1.1.2

12 months ago