Skip to content

Instantly share code, notes, and snippets.

View barisbll's full-sized avatar

Barış BALLI barisbll

View GitHub Profile
@barisbll
barisbll / tsconfig.json
Created September 4, 2022 11:52
ts-debug/ projects's tsconfig file
{
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"sourceMap": true,
"strict": true,
@barisbll
barisbll / package.json
Last active September 4, 2022 12:14
ts-debug/package.json
{
"name": "ts-debugging",
"version": "1.0.0",
"description": "A tutorial repository, created to have a debug example for the medium article",
"main": "index.js",
"scripts": {
"start:dev" : "nodemon ./src/index.ts",
"start:debug" : "nodemon --inspect src/entry.ts"
"build": "tsc"
},
@barisbll
barisbll / nodemon.json
Created September 4, 2022 12:01
ts-debug/nodemon.json
{
"restartable": "rs",
"ignore": [".git", "node_modules/**/node_modules"],
"verbose": true,
"execMap": {
"ts": "node --require ts-node/register"
},
"watch": ["src/"],
"env": {
"NODE_ENV": "development"
@barisbll
barisbll / index.ts
Created September 4, 2022 12:16
ts-debug/index.ts
import express, { Request, Response } from 'express';
const app = express();
app.get('/_healthcheck', (req: Request, res: Response) => {
res.json({ uptime: process.uptime() });
});
app.get('/areWeDebugging?', (req: Request, res: Response) => {
res.json({ hellYeah: true });
@barisbll
barisbll / launch.json
Created September 4, 2022 12:31
ts-debug/launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"port": 9229,
"name": "Attach to port",
"sourceMaps": true,
"skipFiles": ["<node_internals>/**"],
@barisbll
barisbll / jest.config.ts
Created October 8, 2022 17:24
Configuration of the jest file, comments excluded
export default {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: [
'/node_modules/',
'/src/db/',
@barisbll
barisbll / .eslintrc.json
Created October 8, 2022 17:34
Eslint configuration file after jest plugin added
module.exports = {
env: {
commonjs: true,
es2021: true,
node: true,
'jest/globals': true,
},
extends: ['airbnb-base'],
parser: '@typescript-eslint/parser',
parserOptions: {
@barisbll
barisbll / Server.ts
Last active October 9, 2022 07:43
Server class that returns express app as a singleton
import compression from 'compression';
import cors from 'cors';
import express, { Express } from 'express';
import 'reflect-metadata';
import { createRouter as routes } from '../api/rest/v1/routes/routes';
import logger from '../config/logger';
import morganMiddleware from '../config/morgan';
export class Server {
private static app: Express;
@barisbll
barisbll / index.ts
Created October 8, 2022 17:45
Usage of our singleton express application in index.ts
import { Express } from 'express';
import config from './config/config';
import AppDataSource from './config/data-source';
import logger from './config/logger';
import { errorHandler } from './util/customError';
import { Server } from './util/Server';
const app = Server.getServer();
// eslint-disable-next-line no-shadow
@barisbll
barisbll / Dummy.test.ts
Created October 8, 2022 17:48
Test file example with our new jest setup
import { Request, Response } from 'express';
// eslint-disable-next-line import/no-extraneous-dependencies
import request from 'supertest';
import { Server } from '../../../../../../util/Server';
import { DummyController } from '../Auth.controller';
describe('DummyController', () => {
const dummyController = new AuthController();
describe('getTest', () => {