From 9452dcf90e251f67c8bc97fba422babf6dd920fe Mon Sep 17 00:00:00 2001 From: Nikola Petrov Date: Tue, 16 Jul 2024 14:22:33 +0200 Subject: [PATCH] UP app.jst -> ts --- app.js => app.ts | 12 +++++------- package.json | 1 - tsconfig.json | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) rename app.js => app.ts (77%) create mode 100644 tsconfig.json diff --git a/app.js b/app.ts similarity index 77% rename from app.js rename to app.ts index f96c2fe..5270c7c 100644 --- a/app.js +++ b/app.ts @@ -1,7 +1,6 @@ -var express = require('express'); -var path = require('path'); -var logger = require('morgan'); -const http = require('http'); +import express from "express"; +import path from 'path' +import morgan from 'morgan' const hostname = '127.0.0.1'; const httpPort = 4080; @@ -15,12 +14,11 @@ var db = mongoose.connection; db.on('error', console.error.bind(console, 'MongoDB connection error:')); var app = express(); -const httpServer = http.createServer(app); app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'hbs'); -app.use(logger('dev')); +app.use(morgan('dev')); app.use(express.json()); app.use(express.urlencoded({ extended: false })); app.use(express.static(path.join(__dirname, 'public'))); @@ -31,6 +29,6 @@ var apiRouter = require('./routes/api/apiRouter'); app.use('/', mainRouter); app.use('/api', apiRouter); -httpServer.listen(httpPort, () => { +app.listen(httpPort, () => { console.log(`Server running at http://${hostname}:${httpPort}/`); }); \ No newline at end of file diff --git a/package.json b/package.json index 8fcbfa1..c285ed5 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "express": "^4.18.2", "@types/express": "^4.17.21", "hbs": "^4.2.0", - "http": "^0.0.1-security", "mongoose": "^7.5.2", "morgan": "~1.9.1", "@types/morgan": "^1.9.9" diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8f2ff00 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,29 @@ +{ + "compilerOptions": { + // Enable latest features + "lib": [ + "ESNext", + "DOM" + ], + "target": "ESNext", + "module": "ESNext", + "moduleDetection": "force", + "jsx": "react-jsx", + "allowJs": true, + // Bundler mode + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "verbatimModuleSyntax": true, + "noEmit": true, + "resolveJsonModule": true, + "esModuleInterop": true, + // Best practices + "strict": true, + "skipLibCheck": true, + "noFallthroughCasesInSwitch": true, + // Some stricter flags (disabled by default) + "noUnusedLocals": false, + "noUnusedParameters": false, + "noPropertyAccessFromIndexSignature": false + } +} \ No newline at end of file