4.2.207 • Published 10 months ago

@open-stock/stock-universal-server v4.2.207

Weekly downloads
-
License
ISC
Repository
-
Last release
10 months 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

4.2.207

10 months ago

4.2.206

10 months ago

4.2.204

10 months ago

4.2.205

10 months ago

4.2.202

10 months ago

4.2.203

10 months ago

4.2.200

10 months ago

4.2.201

10 months ago

4.2.194

10 months ago

4.2.195

10 months ago

4.2.192

10 months ago

4.2.193

10 months ago

4.2.190

10 months ago

4.2.191

10 months ago

4.2.198

10 months ago

4.2.199

10 months ago

4.2.196

10 months ago

4.2.197

10 months ago

4.2.189

10 months ago

4.2.183

10 months ago

4.2.184

10 months ago

4.2.181

10 months ago

4.2.182

10 months ago

4.2.180

10 months ago

4.2.187

10 months ago

4.2.188

10 months ago

4.2.185

10 months ago

4.2.186

10 months ago

4.2.172

11 months ago

4.2.173

11 months ago

4.2.170

11 months ago

4.2.171

11 months ago

4.2.178

10 months ago

4.2.179

10 months ago

4.2.176

10 months ago

4.2.177

10 months ago

4.2.174

11 months ago

4.2.175

10 months ago

4.2.167

11 months ago

4.2.168

11 months ago

4.2.165

11 months ago

4.2.166

11 months ago

4.2.164

11 months ago

4.2.163

11 months ago

4.2.161

11 months ago

4.2.162

11 months ago

4.2.160

11 months ago

4.2.158

11 months ago

4.2.159

11 months ago

4.2.156

11 months ago

4.2.157

11 months ago

4.2.154

11 months ago

4.2.155

11 months ago

4.2.153

11 months ago

4.2.151

11 months ago

4.2.152

11 months ago

4.2.149

12 months ago

4.2.150

12 months ago

4.2.147

12 months ago

4.2.148

12 months ago

4.2.146

12 months ago

4.2.138

12 months ago

4.2.139

12 months ago

4.2.140

12 months ago

4.2.143

12 months ago

4.2.144

12 months ago

4.2.141

12 months ago

4.2.142

12 months ago

4.2.129

12 months ago

4.2.127

12 months ago

4.2.128

12 months ago

4.2.136

12 months ago

4.2.137

12 months ago

4.2.134

12 months ago

4.2.135

12 months ago

4.2.132

12 months ago

4.2.133

12 months ago

4.2.130

12 months ago

4.2.131

12 months ago

4.2.118

12 months ago

4.2.119

12 months ago

4.2.116

12 months ago

4.2.117

12 months ago

4.2.125

12 months ago

4.2.126

12 months ago

4.2.123

12 months ago

4.2.124

12 months ago

4.2.121

12 months ago

4.2.122

12 months ago

4.2.120

12 months ago

4.2.114

12 months ago

4.2.115

12 months ago

4.2.112

12 months ago

4.2.113

12 months ago

4.2.110

12 months ago

4.2.111

12 months ago

4.1.8

1 year ago

4.1.7

1 year ago

4.1.9

1 year ago

4.2.103

12 months ago

4.2.104

12 months ago

4.2.101

12 months ago

4.2.102

12 months ago

4.2.100

12 months ago

4.0.5

1 year ago

4.0.4

1 year ago

4.0.7

1 year ago

4.0.6

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

4.0.3

1 year ago

4.0.2

1 year ago

4.0.9

1 year ago

4.0.8

1 year ago

4.2.20

1 year ago

4.2.21

1 year ago

4.2.22

1 year ago

4.2.28

1 year ago

4.2.29

1 year ago

4.2.24

1 year ago

4.2.25

1 year ago

4.2.26

1 year ago

4.2.10

1 year ago

4.2.11

1 year ago

4.2.12

1 year ago

4.2.17

1 year ago

4.2.18

1 year ago

4.2.19

1 year ago

4.2.13

1 year ago

4.2.14

1 year ago

4.2.15

1 year ago

4.2.16

1 year ago

3.9.9

1 year ago

3.9.8

1 year ago

3.9.3

1 year ago

3.9.2

1 year ago

3.9.1

1 year ago

3.9.0

1 year ago

3.9.7

1 year ago

3.9.6

1 year ago

3.9.5

1 year ago

3.9.4

1 year ago

4.2.80

12 months ago

4.2.81

12 months ago

4.2.86

12 months ago

4.2.87

12 months ago

4.2.88

12 months ago

4.2.89

12 months ago

4.2.82

12 months ago

4.2.83

12 months ago

4.2.84

12 months ago

4.2.85

12 months ago

4.2.70

12 months ago

4.2.75

12 months ago

4.2.76

12 months ago

4.2.77

12 months ago

4.2.78

12 months ago

4.2.71

12 months ago

4.2.72

12 months ago

4.2.73

12 months ago

4.2.74

12 months ago

4.2.79

12 months ago

4.2.90

12 months ago

4.2.91

12 months ago

4.2.92

12 months ago

4.2.97

12 months ago

4.2.98

12 months ago

4.2.99

12 months ago

4.2.93

12 months ago

4.2.94

12 months ago

4.2.95

12 months ago

4.2.96

12 months ago

4.2.42

1 year ago

4.2.43

1 year ago

4.2.44

1 year ago

4.2.45

1 year ago

4.2.40

1 year ago

4.2.41

1 year ago

4.2.46

1 year ago

4.2.47

1 year ago

4.2.48

1 year ago

4.2.49

1 year ago

4.2.31

1 year ago

4.2.3

1 year ago

4.2.32

1 year ago

4.2.2

1 year ago

4.2.33

1 year ago

4.2.5

1 year ago

4.2.34

1 year ago

4.2.4

1 year ago

4.2.1

1 year ago

4.2.30

1 year ago

4.2.0

1 year ago

4.2.39

1 year ago

4.2.35

1 year ago

4.2.36

1 year ago

4.2.37

1 year ago

4.2.38

1 year ago

4.2.7

1 year ago

4.2.6

1 year ago

4.2.9

1 year ago

4.2.8

1 year ago

4.2.64

1 year ago

4.2.65

1 year ago

4.2.66

1 year ago

4.2.67

12 months ago

4.2.60

1 year ago

4.2.61

1 year ago

4.2.62

1 year ago

4.2.63

1 year ago

4.2.68

12 months ago

4.2.69

12 months ago

4.2.109

12 months ago

4.2.107

12 months ago

4.2.108

12 months ago

4.2.105

12 months ago

4.2.106

12 months ago

4.2.53

1 year ago

4.1.4

1 year ago

4.2.54

1 year ago

4.1.3

1 year ago

4.2.55

1 year ago

4.1.6

1 year ago

4.2.56

1 year ago

4.1.5

1 year ago

4.1.0

1 year ago

4.2.50

1 year ago

4.2.51

1 year ago

4.1.2

1 year ago

4.2.52

1 year ago

4.1.1

1 year ago

4.2.57

1 year ago

4.2.58

1 year ago

4.2.59

1 year ago

3.8.9

1 year ago

3.8.8

1 year ago

3.8.7

1 year ago

3.8.6

1 year ago

3.7.5

1 year ago

3.7.4

1 year ago

3.7.3

1 year ago

3.7.9

1 year ago

3.7.8

1 year ago

3.7.7

1 year ago

3.7.6

1 year ago

3.8.0

1 year ago

3.8.4

1 year ago

3.8.3

1 year ago

3.8.2

1 year ago

3.8.1

1 year ago

3.8.5

1 year ago

3.7.2

1 year ago

3.6.9

1 year ago

3.7.1

1 year ago

3.7.0

1 year ago

3.6.8

1 year ago

3.6.7

1 year ago

3.6.6

1 year ago

3.6.5

1 year ago

3.6.4

1 year ago

3.6.3

1 year ago

3.6.2

1 year ago

3.6.1

1 year ago

3.6.0

1 year ago

3.5.7

1 year ago

3.5.6

1 year ago

3.5.9

1 year ago

3.5.8

1 year ago

3.5.3

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.5.5

1 year ago

3.5.4

1 year ago

3.4.4

1 year ago

3.4.3

1 year ago

3.4.2

1 year ago

3.4.1

1 year ago

3.4.8

1 year ago

3.4.7

1 year ago

3.4.6

1 year ago

3.4.5

1 year ago

3.4.9

1 year ago

3.3.9

1 year ago

3.3.8

1 year ago

3.3.7

1 year ago

3.2.6

1 year ago

3.2.8

1 year ago

3.2.7

1 year ago

3.4.0

1 year ago

3.3.1

1 year ago

3.3.0

1 year ago

3.3.5

1 year ago

3.3.4

1 year ago

3.3.3

1 year ago

3.3.2

1 year ago

3.2.4

1 year ago

3.2.2

1 year ago

3.2.3

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.3

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.1.7

1 year ago

3.1.6

1 year ago

3.1.5

1 year ago

3.1.4

1 year ago

3.1.9

1 year ago

3.1.8

1 year ago

3.0.4

1 year ago

3.0.8

1 year ago

3.0.7

1 year ago

3.0.6

1 year ago

3.0.9

1 year ago

3.0.3

1 year ago

2.8.1

1 year ago

2.8.0

1 year ago

3.0.2

1 year ago

3.0.1

1 year ago

2.9.2

1 year ago

2.7.4

1 year ago

2.9.1

1 year ago

2.7.3

1 year ago

2.9.4

1 year ago

2.9.3

1 year ago

2.7.5

1 year ago

3.0.0

1 year ago

2.9.6

1 year ago

2.7.8

1 year ago

2.9.5

1 year ago

2.7.7

1 year ago

2.9.0

1 year ago

2.7.2

1 year ago

2.7.1

1 year ago

2.8.3

1 year ago

2.8.2

1 year ago

2.8.5

1 year ago

2.8.4

1 year ago

2.8.7

1 year ago

2.8.6

1 year ago

2.8.9

1 year ago

2.8.8

1 year ago

2.7.0

1 year ago

2.6.9

1 year ago

2.6.8

1 year ago

2.6.7

1 year ago

2.6.6

1 year ago

2.6.1

1 year ago

2.6.3

1 year ago

2.6.2

1 year ago

2.6.5

1 year ago

2.6.4

1 year ago

2.6.0

1 year ago

2.5.8

1 year ago

2.5.7

1 year ago

2.5.9

1 year ago

2.5.6

1 year ago

2.5.5

1 year ago

2.5.0

1 year ago

2.5.2

1 year ago

2.5.1

1 year ago

2.5.4

1 year ago

2.5.3

1 year ago

2.4.8

2 years ago

2.4.1

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.4.5

2 years ago

2.4.4

2 years ago

2.4.7

2 years ago

2.4.6

2 years ago

2.4.0

2 years ago

2.3.2

2 years ago

2.3.6

2 years ago

2.3.5

2 years ago

2.3.7

2 years ago

2.3.1

2 years ago

2.3.0

2 years ago

2.1.2

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.4

2 years ago

2.2.5

2 years ago

2.0.7

2 years ago

2.2.4

2 years ago

2.0.6

2 years ago

2.0.8

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.2.9

2 years ago

2.2.8

2 years ago

1.4.5

2 years ago

1.3.4

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago