4.2.207 • Published 9 months ago

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

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

9 months ago

4.2.206

9 months ago

4.2.204

9 months ago

4.2.205

9 months ago

4.2.202

9 months ago

4.2.203

9 months ago

4.2.200

9 months ago

4.2.201

9 months ago

4.2.194

9 months ago

4.2.195

9 months ago

4.2.192

9 months ago

4.2.193

9 months ago

4.2.190

9 months ago

4.2.191

9 months ago

4.2.198

9 months ago

4.2.199

9 months ago

4.2.196

9 months ago

4.2.197

9 months ago

4.2.189

9 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

9 months ago

4.2.188

9 months ago

4.2.185

9 months ago

4.2.186

9 months ago

4.2.172

10 months ago

4.2.173

10 months ago

4.2.170

10 months ago

4.2.171

10 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

10 months ago

4.2.175

10 months ago

4.2.167

10 months ago

4.2.168

10 months ago

4.2.165

10 months ago

4.2.166

10 months ago

4.2.164

10 months ago

4.2.163

10 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

11 months ago

4.2.150

11 months ago

4.2.147

11 months ago

4.2.148

11 months ago

4.2.146

11 months ago

4.2.138

11 months ago

4.2.139

11 months ago

4.2.140

11 months ago

4.2.143

11 months ago

4.2.144

11 months ago

4.2.141

11 months ago

4.2.142

11 months ago

4.2.129

11 months ago

4.2.127

11 months ago

4.2.128

11 months ago

4.2.136

11 months ago

4.2.137

11 months ago

4.2.134

11 months ago

4.2.135

11 months ago

4.2.132

11 months ago

4.2.133

11 months ago

4.2.130

11 months ago

4.2.131

11 months ago

4.2.118

11 months ago

4.2.119

11 months ago

4.2.116

11 months ago

4.2.117

11 months ago

4.2.125

11 months ago

4.2.126

11 months ago

4.2.123

11 months ago

4.2.124

11 months ago

4.2.121

11 months ago

4.2.122

11 months ago

4.2.120

11 months ago

4.2.114

11 months ago

4.2.115

11 months ago

4.2.112

11 months ago

4.2.113

11 months ago

4.2.110

11 months ago

4.2.111

11 months ago

4.1.8

1 year ago

4.1.7

1 year ago

4.1.9

1 year ago

4.2.103

11 months ago

4.2.104

11 months ago

4.2.101

11 months ago

4.2.102

11 months ago

4.2.100

11 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

11 months ago

4.2.81

11 months ago

4.2.86

11 months ago

4.2.87

11 months ago

4.2.88

11 months ago

4.2.89

11 months ago

4.2.82

11 months ago

4.2.83

11 months ago

4.2.84

11 months ago

4.2.85

11 months ago

4.2.70

11 months ago

4.2.75

11 months ago

4.2.76

11 months ago

4.2.77

11 months ago

4.2.78

11 months ago

4.2.71

11 months ago

4.2.72

11 months ago

4.2.73

11 months ago

4.2.74

11 months ago

4.2.79

11 months ago

4.2.90

11 months ago

4.2.91

11 months ago

4.2.92

11 months ago

4.2.97

11 months ago

4.2.98

11 months ago

4.2.99

11 months ago

4.2.93

11 months ago

4.2.94

11 months ago

4.2.95

11 months ago

4.2.96

11 months ago

4.2.42

12 months ago

4.2.43

12 months ago

4.2.44

12 months ago

4.2.45

12 months ago

4.2.40

12 months ago

4.2.41

12 months ago

4.2.46

12 months ago

4.2.47

12 months ago

4.2.48

12 months ago

4.2.49

12 months 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

12 months ago

4.2.35

12 months ago

4.2.36

12 months ago

4.2.37

12 months ago

4.2.38

12 months 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

12 months ago

4.2.65

12 months ago

4.2.66

12 months ago

4.2.67

11 months ago

4.2.60

12 months ago

4.2.61

12 months ago

4.2.62

12 months ago

4.2.63

12 months ago

4.2.68

11 months ago

4.2.69

11 months ago

4.2.109

11 months ago

4.2.107

11 months ago

4.2.108

11 months ago

4.2.105

11 months ago

4.2.106

11 months ago

4.2.53

12 months ago

4.1.4

1 year ago

4.2.54

12 months ago

4.1.3

1 year ago

4.2.55

12 months ago

4.1.6

1 year ago

4.2.56

12 months ago

4.1.5

1 year ago

4.1.0

1 year ago

4.2.50

12 months ago

4.2.51

12 months ago

4.1.2

1 year ago

4.2.52

12 months ago

4.1.1

1 year ago

4.2.57

12 months ago

4.2.58

12 months ago

4.2.59

12 months 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