at-nestjs-core
v1.0.24
Published
Core module to help you build great microservices.
Downloads
34
Readme
Feina Activa
at-nestjs-core
Description
Core module to help you build great microservices.
Built With
- NestJs (4.6) [ common, core, microservices, testing and websockets ]
- @types [ mongoose ]
- Autobind decorator
- json-webtoken
- kafka-node
- lodash
- md5
- moment
- mongoose
- reflect-metadata
- Rxjs
- Winston
- @types [ node ]
- rimraf
- TypeScript (2.6.2)
- Karma [ chrome-launcher, cli, coverage-istanbul-reporter, jasmine and jasmine-html-reporter ]
- TsLint (5.4.3) [ tslint-eslint-rules and no-unused-expression-chai]
- Nodemon (automatic reloading)
General info about the stack used within this microservice:
- NestJs framework.
- TypeScript language.
- TSLint core rules
- Nodemon is a utility that will monitor for any changes un your source and automatically restart your server.
- Check annex section for in depth details about our Stack.
Configuration
These instructions will get you a built version of at-nestj-core library, providing a set of classes and tools to ease your microservice development.
Prerequisites
Make sure you have
node version >= 8.9.x,
mongo version >= 3.4.x,installed on your system.
- Linux installation here.
- Mac installation here.
- Windows installation here.
Environments
Environment variables
There are several configurable variables in .env:
APP_NAME='My Microservice'
JWT_SECRET_KEY='supersecretkey'
COOKIE_NAME='cookie_field'
MONGO_DB_URI=<string, mongodb uri>
PORT='9000'
TRANSLATE_HOST='http://localhost:9001'
DEFAULT_LANG='ca'
Npm Tasks
Following, we have some package scripts to perform this actions:
- Start project for development purposes.
- Run TSLint.
- Compile TypeScript.
- Build project in dist folder.
- Create a server to work with.
- Watch for file changes and reloads the server.
- Prepare code during publish process.
Commands:
npm start
npm run lint
npm run build
npm run prepare
npm run clean
Development
Installing and Running
For installing on a project, you just need to install the dependency and start the project.
npm install at-nestjs-core
npm start
Contributing
For development purposes,
- Is not recommended to use npm link to test development versions on your projects. We suggest you to generate a built version with:
tsc
and copy these generated files into your microservice dependencies folder npm_modules/at-nestjs-core, replacing published files. After this, you only need to restart your microservice.
You can also use
npm start
script to generate built files on every code update.
Running the tests
To run the tests, you need to type
npm tests
This will execute all the unit tests and create a coverage report of the code.
Publishing new version
To create a new version of this library, you need to upgrade the version field on package.json (check package-lock too), login on your cli as npm owner and type:
npm publish
ANNEX
Folder structure
Creates a ready-to-run microservice with the following directories structure:
.
├── src # Contains files and directories. Core classes to build a microservice.
├.editorconfig
├.gitignore
├.npmignore
├README.md
└──
Built with
1. NestJS
What is it?
NestJS aims to provide an application architecture out of the box which allows for effortless creation of highly testable, scalable, loosely coupled and easily maintainable applications.
- Nestjs is a progressive Node.js framework.
- Is built with TypeScript (preserves compatibility with pure Javascript).
- Combines elements of OOP ( Object Oriented Programming ), FP ( Functional Programming ) and FRP ( Functional Reactive Programming ).
- Makes use of Expres.js.
2. TypeScript
What is it?
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
- In this project, Typescript tools are available via npm (Node.js package manager).
- Use .ts extension in order to indicate that a file will contain code written in TypeScript.
3. Nodemon
Nodemon is a utility that will monitor for any changes on your source code and automatically restart your server.
What it does?
- Automatic restarting of application.
- Detects default extension to monitor.
- Ignores specific files or directories.
- Watches specific directories.