Skip to content

Commit

Permalink
add class App
Browse files Browse the repository at this point in the history
  • Loading branch information
pestsov-v committed Feb 15, 2022
1 parent c0d76ca commit 9bce94b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "dependency-ingection-practice",
"type": "module",
"type": "commonjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev:server": "nodemon ./dist/index.js"
"dev:server": "nodemon ./dist/main.js",
"dev:build": "tsc"
},
"repository": {
"type": "git",
Expand Down
24 changes: 24 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import express, {Express} from 'express';
import { userRouter } from './users/users';
import { Server} from 'http';

export class App {
app: Express;
server: Server;
port: number;

constructor() {
this.app = express()
this.port = 8000;
}

useRoutes() {
this.app.use('/users', userRouter);
}

public async init() {
this.useRoutes();
this.server = this.app.listen(this.port);
console.log(`Сервер запущен на http://localhost:${this.port}`);
}
}
17 changes: 0 additions & 17 deletions src/index.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { App } from "./app";

async function bootstrap() {
const app = new App();
await app.init();
}

bootstrap()
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */

/* Modules */
"module": "ES6", /* Specify what module code is generated. */
"module": "commonjs", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
Expand Down

0 comments on commit 9bce94b

Please sign in to comment.