3.0.2 • Published 3 years ago

@paigesfirstmicroservice/common v3.0.2

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

Create your organization

  • on npm website

Create a new npm package

mkdir common
cd common 
npm init --yes 

package.json

  "name": "@paigesfirstmicroservice/common",
{
  "name": "@paigesfirstmicroservice/common",
  "version": "1.0.13",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "build/**/*"
  ],
  "scripts": {
    "clean": "del ./build/*",
    "build": "npm run clean && tsc",
    "pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "del-cli": "^4.0.0",
    "typescript": "^4.3.2"
  }
}

publish source code

npm login 
git add .
git commit -m "message"
npm publish --access public

Resolving Typescript Issue

Issues

  • There might be differences in out TS settings between the common lib and our services - don't want to deal with that
  • Services might not be written with TS at all!
  • Our common library will be written as Typescript and published as Javascript

on module

tsc --init 
npm install typescript del-cli --save-dev 

create typescript file

mkdir src
cd src
touch index.ts

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./build",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  }
}
tsc

.gitignore

build
node_modules

update only version

npm version patch

with our custom command

git add .
git commit -m "blabla"
# npm run build
# npm publish
npm pub 

Relocating Shared Code

index.ts

export * from "./errors/bad-request-error";
export * from "./errors/custom-error";
export * from "./errors/database-connection-error";
export * from "./errors/not-authorized-error";
export * from "./errors/not-found-error";
export * from "./errors/request-validation-error";

export * from "./middlewares/current-user";
export * from "./middlewares/error-handler";
export * from "./middlewares/require-auth";
export * from "./middlewares/validate-request";

get necessary dependencies

{
  "name": "@paigesfirstmicroservice/common",
  "version": "1.0.15",
  "description": "",
  "main": "./build/index.js",
  "types": "./build/index.d.ts",
  "files": [
    "build/**/*"
  ],
  "scripts": {
    "clean": "del ./build/*",
    "build": "npm run clean && tsc",
    "pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "del-cli": "^4.0.1",
    "typescript": "^4.3.5"
  },
  "dependencies": {
    "@types/cookie-session": "^2.0.43",
    "@types/express": "^4.17.13",
    "@types/jsonwebtoken": "^8.5.5",
    "cookie-session": "^1.4.0",
    "express": "^4.17.1",
    "express-validator": "^6.12.1",
    "jsonwebtoken": "^8.5.1"
  }
}

Import our common modules

npm install @paigesfirstmicroservice/common
import { errorHandler, NotFoundError } from "@paigesfirstmicroservice/common";

Updating Common Modules

npm update @paigesfirstmicroservice/common
3.0.2

3 years ago

1.1.9

3 years ago

1.1.7

3 years ago

1.1.5

3 years ago

1.1.2

3 years ago

2.0.1

3 years ago

1.1.1

3 years ago

1.0.28

3 years ago

1.0.25

3 years ago

1.0.23

3 years ago

1.0.21

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.0

3 years ago