Browse Source

Update NestJS ( node version, NestJS version, cluster mode) (#5064)

* Swtich nest to run in produciton mode

* Update to lastest nestjs version

* Use cluster mode for nestjs

* Update README and fix node version for nestjs
Svetlozar Argirov 5 years ago
parent
commit
a31cde9f92

+ 2 - 0
frameworks/TypeScript/nest/.dockerignore

@@ -0,0 +1,2 @@
+node_modules/
+dist/

+ 4 - 1
frameworks/TypeScript/nest/.gitignore

@@ -17,6 +17,7 @@ typings/
 
 
 # Optional npm cache directory
 # Optional npm cache directory
 .npm
 .npm
+.npmrc
 
 
 # Output of 'npm pack'
 # Output of 'npm pack'
 *.tgz
 *.tgz
@@ -29,4 +30,6 @@ typings/
 
 
 tslint.json
 tslint.json
 
 
-*.spec.ts
+*.spec.ts
+
+dist/

+ 2 - 2
frameworks/TypeScript/nest/README.md

@@ -5,8 +5,8 @@ This is the Nest portion of a [benchmarking test suite](../).
 
 
 ## Infrastructure Software Versions
 ## Infrastructure Software Versions
 The tests were run with:
 The tests were run with:
-* [NestJS v5.1.0](https://docs.nestjs.com/)
-* [pg 7.5.0](https://node-postgres.com/)
+* [NestJS v6.6.7](https://docs.nestjs.com/)
+* [pg 7.12.1](https://node-postgres.com/)
 
 
 ## Resources
 ## Resources
 * http://nodejs.org/api/cluster.html
 * http://nodejs.org/api/cluster.html

+ 3 - 3
frameworks/TypeScript/nest/nestjs.dockerfile

@@ -1,9 +1,9 @@
-FROM node:10.3.0
+FROM node:12.3.1-slim
 
 
 COPY ./ ./
 COPY ./ ./
 
 
 RUN yarn install
 RUN yarn install
 
 
-# ENV NODE_ENV production
+ENV NODE_ENV production
 
 
-CMD ["yarn", "start"]
+CMD ["yarn", "start:prod"]

+ 2 - 2
frameworks/TypeScript/nest/ormconfig.json → frameworks/TypeScript/nest/ormconfig.js

@@ -1,4 +1,4 @@
-{
+module.exports = {
     "type": "postgres",
     "type": "postgres",
     "host": "tfb-database",
     "host": "tfb-database",
     "port": 5432,
     "port": 5432,
@@ -7,5 +7,5 @@
     "database": "hello_world",
     "database": "hello_world",
     "synchronize":false,
     "synchronize":false,
     "logging": false,
     "logging": false,
-    "entities": ["./src/**/*.entity.ts", "./dist/**/*.entity.js"]
+    "entities": process.env.NODE_ENV === 'production' ? ["./dist/**/*.entity.js"] : ["./dist/**/*.entity.js", "./src/**/*.entity.ts"]
 }
 }

+ 30 - 28
frameworks/TypeScript/nest/package.json

@@ -13,36 +13,38 @@
     "start:prod": "node dist/main.js"
     "start:prod": "node dist/main.js"
   },
   },
   "dependencies": {
   "dependencies": {
-    "@nestjs/common": "5.1.0",
-    "@nestjs/core": "5.1.0",
-    "@nestjs/typeorm": "5.2.2",
-    "dotenv": "6.0.0",
-    "fastify": "1.12.1",
-    "fastify-formbody": "2.0.1",
-    "pg": "7.5.0",
-    "reflect-metadata": "0.1.12",
-    "rxjs": "6.2.2",
-    "typeorm": "0.2.7",
-    "typescript": "3.0.1"
+    "@nestjs/common": "6.6.7",
+    "@nestjs/core": "6.6.7",
+    "@nestjs/platform-express": "^6.0.0",
+    "@nestjs/typeorm": "6.1.3",
+    "dotenv": "8.1.0",
+    "express-cluster": "^0.0.5",
+    "fastify": "2.8.0",
+    "fastify-formbody": "3.1.0",
+    "pg": "7.12.1",
+    "reflect-metadata": "0.1.13",
+    "rxjs": "6.5.3",
+    "typeorm": "0.2.19",
+    "typescript": "3.6.3"
   },
   },
   "devDependencies": {
   "devDependencies": {
-    "@nestjs/testing": "5.1.0",
-    "@types/express": "4.16.0",
-    "@types/jest": "23.3.1",
-    "@types/node": "10.7.1",
-    "@types/supertest": "2.0.5",
-    "jest": "23.5.0",
-    "nodemon": "1.18.3",
-    "prettier": "1.14.2",
-    "rimraf": "2.6.2",
-    "supertest": "3.1.0",
-    "ts-jest": "23.1.3",
-    "ts-loader": "4.4.2",
-    "ts-node": "7.0.1",
-    "tsconfig-paths": "3.5.0",
-    "tslint": "5.11.0",
-    "webpack": "4.16.5",
-    "webpack-cli": "3.1.0",
+    "@nestjs/testing": "6.6.7",
+    "@types/express": "4.17.1",
+    "@types/jest": "24.0.18",
+    "@types/node": "12.7.5",
+    "@types/supertest": "2.0.8",
+    "jest": "24.9.0",
+    "nodemon": "1.19.2",
+    "prettier": "1.18.2",
+    "rimraf": "3.0.0",
+    "supertest": "4.0.2",
+    "ts-jest": "24.1.0",
+    "ts-loader": "6.1.0",
+    "ts-node": "8.3.0",
+    "tsconfig-paths": "3.9.0",
+    "tslint": "5.20.0",
+    "webpack": "4.40.2",
+    "webpack-cli": "3.3.8",
     "webpack-node-externals": "1.7.2"
     "webpack-node-externals": "1.7.2"
   },
   },
   "jest": {
   "jest": {

+ 0 - 1
frameworks/TypeScript/nest/src/bench/bench.module.ts

@@ -10,7 +10,6 @@ import { WorldEntity } from './../models/world.entity';
   imports: [TypeOrmModule.forFeature([WorldEntity])],
   imports: [TypeOrmModule.forFeature([WorldEntity])],
   controllers: [BenchController],
   controllers: [BenchController],
   providers: [BenchService],
   providers: [BenchService],
-  components: [BenchService],
   exports: [BenchService],
   exports: [BenchService],
 })
 })
 export class BenchModule {}
 export class BenchModule {}

+ 1 - 1
frameworks/TypeScript/nest/src/bench/bench.service.ts

@@ -1,6 +1,6 @@
 import { Injectable } from '@nestjs/common';
 import { Injectable } from '@nestjs/common';
 import { Repository } from 'typeorm';
 import { Repository } from 'typeorm';
-import { WorldEntity } from 'models/world.entity';
+import { WorldEntity } from '../models/world.entity';
 import { InjectRepository } from '@nestjs/typeorm';
 import { InjectRepository } from '@nestjs/typeorm';
 
 
 @Injectable()
 @Injectable()

+ 9 - 4
frameworks/TypeScript/nest/src/main.ts

@@ -1,13 +1,18 @@
 import 'dotenv/config';
 import 'dotenv/config';
-import { NestFactory, FastifyAdapter } from '@nestjs/core';
+import { NestFactory } from '@nestjs/core';
 import { AppModule } from './app.module';
 import { AppModule } from './app.module';
 import { Logger } from '@nestjs/common';
 import { Logger } from '@nestjs/common';
+import * as cluster from 'express-cluster';
+
 
 
 const port = process.env.PORT || 8080;
 const port = process.env.PORT || 8080;
 
 
 async function bootstrap() {
 async function bootstrap() {
-  const app = await NestFactory.create(AppModule);
-  await app.listen(port);
-  Logger.log(`Listening on port ${port}`, 'Nest Server');
+  await cluster(async (w)=>{
+    const app = await NestFactory.create(AppModule);
+    Logger.log(`Listening on port ${port}`, 'Nest Server');
+    return  app.listen(port)
+  }, {});
 }
 }
+
 bootstrap();
 bootstrap();