Giter Site home page Giter Site logo

ljlm0402 / typescript-express-starter Goto Github PK

View Code? Open in Web Editor NEW
2.6K 27.0 399.0 38.56 MB

๐Ÿ“˜ Quick and Easy TypeScript Express Starter

Home Page: http://npm.im/typescript-express-starter

License: MIT License

JavaScript 11.54% TypeScript 84.51% Shell 0.03% Makefile 3.93%
typescript express jest nodejs mongoose sequelize typeorm docker eslint prettier

typescript-express-starter's Introduction


Project Logo

TypeScript Express Starter

๐Ÿš€ Express RESTful API Boilerplate Using TypeScript

npm Info

npm Version npm Release Version npm Downloads npm Package License

github Stars github Forks github Contributors github Issues



๐Ÿ˜Ž Introducing The Project

Express consists of JavaScript, which makes it vulnerable to type definitions.

That's why we avoid supersets with starter packages that introduce TypeScript.

The package is configured to use TypeScript instead of JavaScript.

The project referred to express-generator-typescript

๐Ÿค” What is Express ?

Express is a fast, open and concise web framework and is a Node.js based project.

๐Ÿš€ Quick Start

Install with the npm Global Package

$ npm install -g typescript-express-starter

Run npx to Install The Package

npx is a tool in the JavaScript package management module, npm.

This is a tool that allows you to run the npm package on a single run without installing the package.

If you do not enter a project name, it defaults to typescript-express-starter.

$ npx typescript-express-starter "project name"

Select a Templates

Example Cli

Start your typescript-express-starter app in development mode at http://localhost:3000/

Template Type

Name Description
Default Express Default
Routing Controllers Create structured, declarative and beautifully organized class-based controllers with heavy decorators usage
Sequelize Easy to use multi SQL dialect ORM for Node.js
Mongoose MongoDB Object Modeling(ODM) designed to work in an asynchronous environment
TypeORM An ORM that can run in Node.js and Others
Prisma Modern Database Access for TypeScript & Node.js
Knex SQL query builder for Postgres, MySQL, MariaDB, SQLite3 and Oracle
GraphQL query language for APIs and a runtime for fulfilling those queries with your existing data
Typegoose Define Mongoose models using TypeScript classes
Mikro ORM TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases
Node Postgres node-postgres is a collection of node.js modules for interfacing with your PostgreSQL database

Template to be developed

Name Description
Sequelize Typescript Decorators and some other features for sequelize
TS SQL A SQL database implemented purely in TypeScript type annotations
inversify-express-utils Some utilities for the development of Express application with InversifyJS
postgress typescript
graphql prisma

๐Ÿ›Ž Available Commands for the Server

  • Run the Server in production mode : npm run start or Start typescript-express-starter in VS Code
  • Run the Server in development mode : npm run dev or Dev typescript-express-starter in VS Code
  • Run all unit-tests : npm test or Test typescript-express-starter in VS Code
  • Check for linting errors : npm run lint or Lint typescript-express-starter in VS Code
  • Fix for linting : npm run lint:fix or Lint:Fix typescript-express-starter in VS Code

๐Ÿ’Ž The Package Features

ย ย  ย ย  ย ย 

ย ย  ย ย  ย ย  ย ย  ย ย  ย ย 

ย ย  ย ย  ย ย 

๐Ÿณ Docker :: Container Platform

Docker is a platform for developers and sysadmins to build, run, and share applications with containers.

Docker Install.

  • starts the containers in the background and leaves them running : docker-compose up -d
  • Stops containers and removes containers, networks, volumes, and images : docker-compose down

Modify docker-compose.yml and Dockerfile file to your source code.

โ™ป๏ธ NGINX :: Web Server

NGINX is a web server that can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache.

Proxying is typically used to distribute the load among several servers, seamlessly show content from different websites, or pass requests for processing to application servers over protocols other than HTTP.

When NGINX proxies a request, it sends the request to a specified proxied server, fetches the response, and sends it back to the client.

Modify nginx.conf file to your source code.

โœจ ESLint, Prettier :: Code Formatter

Prettier is an opinionated code formatter.

ESLint, Find and fix problems in your JavaScript code

It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary.

  1. Install VSCode Extension Prettier, ESLint

  2. CMD + Shift + P (Mac Os) or Ctrl + Shift + P (Windows)

  3. Format Selection With

  4. Configure Default Formatter...

  5. Prettier - Code formatter

Formatter Setting

Palantir, the backers behind TSLint announced in 2019 that they would be deprecating TSLint in favor of supporting typescript-eslint in order to benefit the community. So, migration from TSLint to ESLint.

๐Ÿ“— Swagger :: API Document

Swagger is Simplify API development for users, teams, and enterprises with the Swagger open source and professional toolset.

Easily used by Swagger to design and document APIs at scale.

Start your app in development mode at http://localhost:3000/api-docs

Modify swagger.yaml file to your source code.

๐ŸŒ REST Client :: HTTP Client Tools

REST Client allows you to send HTTP request and view the response in Visual Studio Code directly.

VSCode Extension REST Client Install.

Modify *.http file in src/http folder to your source code.

๐Ÿ”ฎ PM2 :: Advanced, Production process manager for Node.js

PM2 is a daemon process manager that will help you manage and keep your application online 24/7.

  • production mode :: npm run deploy:prod or pm2 start ecosystem.config.js --only prod
  • development mode :: npm run deploy:dev or pm2 start ecosystem.config.js --only dev

Modify ecosystem.config.js file to your source code.

๐ŸŽ SWC :: a super-fast JavaScript / TypeScript compiler

SWC is an extensible Rust-based platform for the next generation of fast developer tools.

SWC is 20x faster than Babel on a single thread and 70x faster on four cores.

  • tsc build :: npm run build
  • swc build :: npm run build:swc

Modify .swcrc file to your source code.

๐Ÿ’„ Makefile :: This is a setting file of the make program used to make the compilation that occurs repeatedly on Linux

Makefiles are used to help decide which parts of a large program need to be recompiled.

  • help :: make help

Modify Makefile file to your source code.

๐Ÿ—‚ Code Structure (default)

โ”‚
โ”œโ”€โ”€๐Ÿ“‚ .vscode
โ”‚  โ”œโ”€โ”€ launch.json
โ”‚  โ””โ”€โ”€ settings.json
โ”‚
โ”œโ”€โ”€๐Ÿ“‚ src
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ config
โ”‚  โ”‚  โ””โ”€โ”€ index.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ controllers
โ”‚  โ”‚  โ”œโ”€โ”€ auth.controller.ts
โ”‚  โ”‚  โ””โ”€โ”€ users.controller.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ dtos
โ”‚  โ”‚  โ””โ”€โ”€ users.dto.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ exceptions
โ”‚  โ”‚  โ””โ”€โ”€ httpException.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ http
โ”‚  โ”‚  โ”œโ”€โ”€ auth.http
โ”‚  โ”‚  โ””โ”€โ”€ users.http
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ interfaces
โ”‚  โ”‚  โ”œโ”€โ”€ auth.interface.ts
โ”‚  โ”‚  โ”œโ”€โ”€ routes.interface.ts
โ”‚  โ”‚  โ””โ”€โ”€ users.interface.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ middlewares
โ”‚  โ”‚  โ”œโ”€โ”€ auth.middleware.ts
โ”‚  โ”‚  โ”œโ”€โ”€ error.middleware.ts
โ”‚  โ”‚  โ””โ”€โ”€ validation.middleware.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ models
โ”‚  โ”‚  โ””โ”€โ”€ users.model.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ routes
โ”‚  โ”‚  โ”œโ”€โ”€ auth.route.ts
โ”‚  โ”‚  โ””โ”€โ”€ users.route.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ services
โ”‚  โ”‚  โ”œโ”€โ”€ auth.service.ts
โ”‚  โ”‚  โ””โ”€โ”€ users.service.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ test
โ”‚  โ”‚  โ”œโ”€โ”€ auth.test.ts
โ”‚  โ”‚  โ””โ”€โ”€ users.test.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€๐Ÿ“‚ utils
โ”‚  โ”‚  โ”œโ”€โ”€ logger.ts
โ”‚  โ”‚  โ””โ”€โ”€ vaildateEnv.ts
โ”‚  โ”‚
โ”‚  โ”œโ”€โ”€ app.ts
โ”‚  โ””โ”€โ”€ server.ts
โ”‚
โ”œโ”€โ”€ .dockerignore
โ”œโ”€โ”€ .editorconfig
โ”œโ”€โ”€ .env.development.local
โ”œโ”€โ”€ .env.production.local
โ”œโ”€โ”€ .env.test.local
โ”œโ”€โ”€ .eslintignore
โ”œโ”€โ”€ .eslintrc
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .huskyrc
โ”œโ”€โ”€ .lintstagedrc.json
โ”œโ”€โ”€ .prettierrc
โ”œโ”€โ”€ .swcrc
โ”œโ”€โ”€ docker-compose.yml
โ”œโ”€โ”€ Dockerfile.dev
โ”œโ”€โ”€ Dockerfile.prod
โ”œโ”€โ”€ ecosystem.config.js
โ”œโ”€โ”€ jest.config.js
โ”œโ”€โ”€ Makefile
โ”œโ”€โ”€ nginx.conf
โ”œโ”€โ”€ nodemon.json
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ swagger.yaml
โ””โ”€โ”€ tsconfig.json

โญ๏ธ Stargazers

Stargazers repo roster for @ljlm0402/typescript-express-starter

๐Ÿด Forkers

Forkers repo roster for @ljlm0402/typescript-express-starter

๐Ÿค Contributors

Contributors repo roster for @ljlm0402/typescript-express-starter

๐Ÿ’ณ License

MIT

๐Ÿ“‘ Recommended Commit Message

When Commit Message
Add Feature โœจ Add Feature
Fix Bug ๐Ÿž Fix Bug
Refactoring Code ๐Ÿ›  Refactoring Code
Install Package ๐Ÿ“ฆ Install Package
Fix Readme ๐Ÿ“š Fix Readme
Update Version ๐ŸŒผ Update Version
New Template ๐ŸŽ‰ New Template

๐Ÿ“ฌ Please request an issue

Please leave a question or question as an issue.

I will do my best to answer and reflect.

Thank you for your interest.

เดฆเตเดฆเดฟหŠแ—œห‹)

typescript-express-starter's People

Contributors

ajvarparadise avatar alanmynah avatar amriksd avatar benjaminudoh10 avatar bityoungjae avatar davidjmstewart avatar dustinnewbold avatar edguy3 avatar engjellavdiu avatar florianmifsud avatar hichemfantar avatar ignatg avatar jagthefriend avatar joaopms avatar jonathanfelicity avatar jongio avatar joshuaoloduca avatar kubarozkwitalski avatar ljlm0402 avatar malavancs avatar markuslaubscher avatar n2ptune avatar noelzappy avatar pablosproject avatar seanpmaxwell avatar sonbyungjun avatar swtpumpkin avatar tamzidkarim avatar whatifwedigdeeper avatar yeondam88 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typescript-express-starter's Issues

How best to handle errors that come from database constraints?

Using the starter, if you have a service function do something that violates a database constraint (for example on uniqueness or table relationships), the error is uncaught and the API returns a 500. What is a good strategy for catching these errors and returning a 4xx and a better error message?

Unable to start the server because Sequelize V6 is not yet supported by sequelize-typescript

This starter repository is not working anymore because of a recent major release of Sequelize V6. We are getting the following error:

TSError: โจฏ Unable to compile TypeScript:
src/models/index.model.ts(25,22): error TS2769: No overload matches this call.
  The last overload gave the following error.
    Type 'typeof User' is not assignable to type 'string | ModelCtor<Model<any, any>>'.
      Type 'typeof User' is not assignable to type 'ModelCtor<Model<any, any>>'.
        Type 'typeof User' is not assignable to type 'typeof Model'.
          Construct signature return types 'User' and 'Model<T, T2>' are incompatible.
            The types of '_attributes' are incompatible between these types.
              Type 'User' is not assignable to type 'T'.
                'T' could be instantiated with an arbitrary type which could be unrelated to 'User'.

    at createTSError (D:\___\code\api\node_modules\ts-node\src\index.ts:434:12)
    at reportTSError (D:\___\code\api\node_modules\ts-node\src\index.ts:438:19)
    at getOutput (D:\___\code\api\node_modules\ts-node\src\index.ts:578:36)
    at Object.compile (D:\___\code\api\node_modules\ts-node\src\index.ts:775:32)
    at Module.m._compile (D:\___\code\api\node_modules\ts-node\src\index.ts:858:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Object.require.extensions.<computed> [as .ts] (D:\___\code\api\node_modules\ts-node\src\index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Module.require (internal/modules/cjs/loader.js:1026:19)
[nodemon] app crashed - waiting for file changes before starting...

sequelize-typescript is not yet upgraded to support Sequelize V6.
I think this one is the WIP: sequelize/sequelize-typescript#804

Fix validationMiddleware

Motivation(์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์„ค๋ช…)

If the skipMissingProperties value of validation middleware is set to true, the corresponding function is not performed at all.

However, it is necessary to determine the req data based on dto, and verification of other req data is required.

Proposed Solution(๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์–ป๊ณ ์ž ํ•˜๋Š” ์†”๋ฃจ์…˜)

For example, it is composed of dto = email, password, but if the data of req.body is added as email, password, name, and name data is added, the corresponding verification must be done even if skipMissingProperties = true.

Alternatives(์ œ์•ˆ ๋œ ์†”๋ฃจ์…˜์ด ๋” ๋‚˜์€ ์ด์œ )

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

when i use npx typescript-express-starter "project name"

The files are creating and after sometime it says as below


ร— Please leave this error as an issue
Error: Command failed: npm i -s  bcrypt class-transformer class-validator compression config cookie-parser cors cross-env dotenv envalid express helmet hpp jest jsonwebtoken morgan [email protected] swagger-ui-express ts-jest ts-node typescript winston winston-daily-rotate-file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 1,
  signal: null,
  cmd: 'npm i -s  bcrypt class-transformer class-validator compression config cookie-parser cors cross-env dotenv envalid express helmet hpp jest jsonwebtoken morgan [email protected] swagger-ui-express ts-jest ts-node typescript winston winston-daily-rotate-file',
  stdout: '',
  stderr: ''
}

Todo

  1. Add REST Client
  2. Create TypeORM Template
  3. Fix TSLint -> ESLint

Create a new template knex

Motivation

Create a new template knex

kenx : https://knexjs.org/

Proposed Solution

Creating a new template using knex, SQL Query Builder

Alternatives

To provide a variety of templates

Additional Context

Starting the app throws an error (Ubuntu)

Describe the Bug(๋ฒ„๊ทธ ์„ค๋ช…)

Anytime you tired to npm start (or run the built server), it would fail with:

internal/modules/cjs/loader.js:818
  throw err;
  ^

Error: Cannot find module './'
Require stack:

Version to Reproduce(ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฒ„์ „)

Ubuntu 20.04, Node v12.22.1, npm v6.14.12

Steps to Reproduce(์žฌํ˜„ ์ˆœ์„œ)

  1. Start a new project with Prisma
  2. Run npm install
  3. Run npm start

Expected Behavior(์˜ˆ์ƒ ๋™์ž‘)

Its expected to start the server up on port 3000 but fails.

Actual Behavior(์‹ค์ œ ๋™์ž‘)

Fails and quits server.

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

I fixed this by changing line 4 of server.ts from:

import App from '@app';

to:

import App from './app';

Capture screen(์บก์ณ ํ™”๋ฉด)

image

Fix authMiddleware

Motivation(์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์„ค๋ช…)

Verification of cookie or header authorization

Proposed Solution(๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์–ป๊ณ ์ž ํ•˜๋Š” ์†”๋ฃจ์…˜)

Alternatives(์ œ์•ˆ ๋œ ์†”๋ฃจ์…˜์ด ๋” ๋‚˜์€ ์ด์œ )

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

Feature Request: Sequelize-cli Integration

Hi guys! Great work on this project! Thanks for saving me a lot of headaches!

If there could be some sequelize-cli integration on this project(to generate migration and etc), or document on how to set it up, it'd be great! Thanks again for your work.

Unable to use postgresql with this

Tried to set sequelize during the setup. Later, modified the configs and environments to use postgres but that doesn't allow me to use my postgresql server :( Am I doing it incorrectly?

Generating Migrations and Models with Sequelize

Summary

Is there any specific CLI command to generate all the interfaces for Sequelize Models etc using just a single command in your project? Turns out sequelize migrate creates plain old js files.

Helmet is not a function

When trying to run the application, an exception is being thrown:

this.app.use(helmet()); ^ TypeError: helmet_1.default is not a function at App.initializeMiddlewares (C:\Source\TnT\TnT2\src\app.ts:39:26) at new App (C:\Source\TnT\TnT2\src\app.ts:20:10) at Object.<anonymous> (C:\Source\TnT\TnT2\src\server.ts:10:13) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Module.m._compile (C:\Source\TnT\TnT2\node_modules\ts-node\src\index.ts:1043:23) at Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Object.require.extensions.<computed> [as .ts] (C:\Source\TnT\TnT2\node_modules\ts-node\src\index.ts:1046:12) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)

The fix seems to be changing the import statement in app.ts from:

import helmet from 'helmet';

to

import * as helmet from 'helmet'

I'm happy to submit to resolve this myself, but I'm not sure if this is by design or not.

Create a new template graphql

Motivation(์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์„ค๋ช…)

Create a new template graphql

graphql: https://graphql.org/

Proposed Solution(๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์–ป๊ณ ์ž ํ•˜๋Š” ์†”๋ฃจ์…˜)

Creating a new template using graphql, A query language for your API

Alternatives(์ œ์•ˆ ๋œ ์†”๋ฃจ์…˜์ด ๋” ๋‚˜์€ ์ด์œ )

To provide a variety of templates

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

Why aren't the services static?

Is there any reason that classes like userService aren't static?

Wouldn't it be easier to call the method without having to initiate an object?

ReferenceError: exports is not defined

default template
node v15.11.0

Info: === tsc-alias starting ===
Info: 11 files were affected!
file:///Users/user/Desktop/Code/butter/dist/server.js:2
Object.defineProperty(exports, "__esModule", { value: true });
^

ReferenceError: exports is not defined
at file:///Users/user/Desktop/Code/butter/dist/server.js:2:23
at ModuleJob.run (node:internal/modules/esm/module_job:154:23)
at async Loader.import (node:internal/modules/esm/loader:166:24)

tsconfig.json
{ "compileOnSave": false, "compilerOptions": { "target": "es2017", "lib": ["es2017", "esnext.asynciterable"], "typeRoots": ["node_modules/@types"], "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, "forceConsistentCasingInFileNames": true, "moduleResolution": "node", "module": "commonjs", "pretty": true, "sourceMap": true, "declaration": true, "outDir": "./dist", "skipLibCheck": true, "allowJs": true, "noEmit": false, "esModuleInterop": true, "resolveJsonModule": true, "importHelpers": true, "baseUrl": "src", "paths": { "@app": ["app"], "@controllers/*": ["controllers/*"], "@dtos/*": ["dtos/*"], "@exceptions/*": ["exceptions/*"], "@interfaces/*": ["interfaces/*"], "@middlewares/*": ["middlewares/*"], "@models/*": ["models/*"], "@routes/*": ["routes/*"], "@services/*": ["services/*"], "@utils/*": ["utils/*"] } }, "include": ["src/**/*.ts", "src/**/*.json", ".env"], "exclude": ["node_modules"] }

New Feature pm2

Motivation

Adding a new function pm2

pm2 : https://pm2.keymetrics.io/

Proposed Solution

Adding a new function pm2, ADVANCED, PRODUCTION PROCESS MANAGER FOR NODE.JS

Alternatives

Cluster mode, Load balancing, keep applications alive forever

Additional Context

Thank You

Thank you bro, It' help me a lot.
:)

generated issue

โœ– Please leave this error as an issue
Error: Command failed: npm i -s bcrypt class-transformer class-validator cookie-parser cors cross-env dotenv envalid express helmet hpp jest jsonwebtoken morgan swagger-jsdoc swagger-ui-express ts-jest ts-node typescript mysql2 sequelize sequelize-typescript

at ChildProcess.exithandler (child_process.js:303:12)
at ChildProcess.emit (events.js:315:20)
at maybeClose (internal/child_process.js:1021:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5) {

killed: false,
code: 1,
signal: null,
cmd: 'npm i -s bcrypt class-transformer class-validator cookie-parser cors cross-env dotenv envalid express helmet hpp jest jsonwebtoken morgan swagger-jsdoc swagger-ui-express ts-jest ts-node typescript mysql2 sequelize sequelize-typescript',
stdout: "Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/asya/prjcts/adminkoSwaponline/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/home/asya/prjcts/adminkoSwaponline/node_modules/bcrypt/lib/binding/napi-v3 --napi_version=6 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)\n",
stderr: ''
}

No swagger.yaml

Hey guys I just created a project via npx and I was trying to get in to the swagger in the scratch project and it not working. There is no even a swagger.yaml file.

Mongoose Template Build Error

Describe the Bug

mongoose template tsc build error

Version to Reproduce

node : v14.8.0(LTS)
npm : v6.14.9
mongoose : ^5.11.8
@types/mongoose : ^5.10.3

Steps to Reproduce & Version

  1. mongoose template created
  2. run script npm run start or 'num run build'

If applicable, add a link to a test case (as a zip file or link to a repository we can clone).

Expected Behavior

A clear and concise description of what you expected to happen.

Actual Behavior

image

A clear and concise description of what actually happened.

If applicable, add screenshots to help explain your problem.

Additional Context

Add any other context about the problem here.

Unit Tests Errors describe logout (cookie)

Describe the Bug

Cookie data does not exist, causing middleware errors

Steps to Reproduce

auth.test.ts files describe logout

Expected Behavior

Actual Behavior

Additional Context

Capture screen

image

Possible issue with sequalize logout function - security issue?

Describe the Bug(๋ฒ„๊ทธ ์„ค๋ช…)

On line 44 of the uth.service.ts file in the sequalize folder I have noticed that you search for a user only by their password. I am not sure what the user being returned is used for (as they are being logged out) but it seems to me that you could return an incorrect user if 2 users were to use the same password. Suggest changing this to search for user by a unique field or email and password combination?

Version to Reproduce(ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฒ„์ „)

Any environment.

Steps to Reproduce(์žฌํ˜„ ์ˆœ์„œ)

  1. Create a user with password "password"
  2. Create a second user with password "password"
  3. Login as the second user
  4. Log out
  5. You will be returned user from step 1 above when you were logged in as user from step 2!

Expected Behavior(์˜ˆ์ƒ ๋™์ž‘)

Should return the user you are logged in as.

Actual Behavior(์‹ค์ œ ๋™์ž‘)

A different user (with the same password) is returned.

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

This same technique seems to be used in TypeORM and mongoose as well. If it is an issue then it probably needs changing in all these.

Capture screen(์บก์ณ ํ™”๋ฉด)

Modify Request type to include typed body

Summary(์š”์•ฝ)

Even though there exists a validationMiddleware that calls plainToClass() and transforms the body object into a class instance, this class instance is not preserved and will need to be transformed again in the route handler.

Additional Details(์ถ”๊ฐ€์ ์ธ ์„ธ๋ถ€ ์‚ฌํ•ญ)

What currently exists in the project in the controller is a simple cast const userData: CreateUserDto = req.body;, but that's lying to the compiler because userData is not actually an instance of CreateUserDto, this can be noticed if the Dto has methods or custom getters or setters. Is this a real concern? Or should we ignore this?
One replacement could be const userData = plainToClass(CreateUserDto, req.body);, but I was thinking that maybe we can make use of the validationMiddleware as it calls plainToClass already.

What do you think?

Default template Unit Tests fail

When running the unit tests in the default version, the auth.test.ts fails:

` src/tests/auth.test.ts:25:36 - error TS2339: Property 'path' does not exist on type 'AuthRoute'.

25                 .post(`${authRoute.path}/signup`)
                                      ~~~~
src/tests/auth.test.ts:41:36 - error TS2339: Property 'path' does not exist on type 'AuthRoute'.

41                 .post(`${authRoute.path}/login`)
                                      ~~~~
src/tests/auth.test.ts:53:36 - error TS2339: Property 'path' does not exist on type 'AuthRoute'.

53                 .post(`${authRoute.path}/logout`)`

Even if this compilation error is fixed, the tests still fail:

FAIL src/tests/auth.test.ts (7.321 s)
โ— Testing Auth โ€บ [POST] /login โ€บ response should have the Set-Cookie header with the Authorization token

expected "Set-Cookie" header field

  at Test._assertHeader (node_modules/supertest/lib/test.js:237:45)
  at Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
  at Test.assert (node_modules/supertest/lib/test.js:173:18)
  at Server.localAssert (node_modules/supertest/lib/test.js:131:12)

โ— Testing Auth โ€บ [POST] /logout โ€บ logout Set-Cookie Authorization=; Max-age=0

expected "Set-Cookie" header field

  at Test._assertHeader (node_modules/supertest/lib/test.js:237:45)
  at Test._assertFunction (node_modules/supertest/lib/test.js:283:11)
  at Test.assert (node_modules/supertest/lib/test.js:173:18)
  at Server.localAssert (node_modules/supertest/lib/test.js:131:12)

In the sequelize template I get the following:

FAIL src/tests/auth.test.ts
โ— Test suite failed to run

src/tests/users.test.ts:15:13 - error TS2740: Type 'typeof User' is missing the following properties from type 'User[]': pop, push, concat, join, and 25 more.

15       const findUser: User[] = userModel;
               ~~~~~~~~
src/tests/users.test.ts:28:40 - error TS2339: Property 'find' does not exist on type 'typeof User'.

28       const findUser: User = userModel.find(user => user.id === userId);
                                          ~~~~
src/tests/users.test.ts:28:45 - error TS7006: Parameter 'user' implicitly has an 'any' type.

28       const findUser: User = userModel.find(user => user.id === userId);
                                               ~~~~
src/tests/users.test.ts:74:44 - error TS2339: Property 'filter' does not exist on type 'typeof User'.

74       const deleteUser: User[] = userModel.filter(user => user.id !== userId);
                                              ~~~~~~
src/tests/users.test.ts:74:51 - error TS7006: Parameter 'user' implicitly has an 'any' type.

74       const deleteUser: User[] = userModel.filter(user => user.id !== userId);
                                                     ~~~~

FAIL src/tests/users.test.ts
โ— Test suite failed to run

src/models/index.model.ts:25:22 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Type 'typeof User' is not assignable to type 'string | ModelCtor<Model<any, any>>'.
      Type 'typeof User' is not assignable to type 'ModelCtor<Model<any, any>>'.
        Type 'typeof User' is not assignable to type 'typeof Model'.
          Construct signature return types 'User' and 'Model<T, T2>' are incompatible.
            The types of '_attributes' are incompatible between these types.
              Type 'User' is not assignable to type 'T'.
                'T' could be instantiated with an arbitrary type which could be unrelated to 'User'.

25 sequelize.addModels([User]);
                        ~~~~

  node_modules/sequelize-typescript/dist/sequelize/sequelize/sequelize.d.ts:16:5
    16     addModels(arg: Array<ModelCtor | string>): any;
           ~~~~~~~~~
    The last overload is declared here.

FAIL src/tests/index.test.ts
โ— Test suite failed to run

TypeError: Cannot read property 'getQueryInterface' of undefined

  at Function.get queryInterface [as queryInterface] (node_modules/sequelize/lib/model.js:55:27)
  at isFunctionMember (node_modules/sequelize-typescript/dist/model/model/model.js:99:25)
  at node_modules/sequelize-typescript/dist/model/model/model.js:96:5
      at Array.filter (<anonymous>)
  at Object.<anonymous> (node_modules/sequelize-typescript/dist/model/model/model.js:95:6)
  at Object.<anonymous> (node_modules/sequelize-typescript/dist/model/shared/model-service.js:3:17)

I've not tried the mongoose version, but I'm guessing that will have similiar issues. I'm guessing these are still work in progress.

Sequelize template seems to be broken

Describe the Bug(๋ฒ„๊ทธ ์„ค๋ช…)

When using the sequelize template and running the project with docker compose up -d I get an error when the node application tries to interact with the database.

Not sure if the templates are suppose to be working examples.

Version to Reproduce(ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฒ„์ „)

Used with Docker

Steps to Reproduce(์žฌํ˜„ ์ˆœ์„œ)

  1. npx typescript-express-starter
  2. select sequelize template
  3. GET request --> http://localhost:3000/users

Expected Behavior(์˜ˆ์ƒ ๋™์ž‘)

Actual Behavior(์‹ค์ œ ๋™์ž‘)

error: [GET] /users >> StatusCode:: 500, Message:: connect ECONNREFUSED 127.0.0.1:3306

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306

at ConnectionManager.connect (/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:116:17)

at processTicksAndRejections (internal/process/task_queues.js:93:5)

at ConnectionManager._connect (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:318:24)

at /app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:250:32

at ConnectionManager.getConnection (/app/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:280:7)

at /app/node_modules/sequelize/lib/sequelize.js:613:26

at MySQLQueryInterface.select (/app/node_modules/sequelize/lib/dialects/abstract/query-interface.js:953:12)

at Function.findAll (/app/node_modules/sequelize/lib/model.js:1753:21)

at UserService.findAllUser (/app/src/services/users.service.ts:12:29)

at UsersController.getUsers (/app/src/controllers/users.controller.ts:11:40) {

parent: Error: connect ECONNREFUSED 127.0.0.1:3306

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '127.0.0.1',

port: 3306,

fatal: true

},

original: Error: connect ECONNREFUSED 127.0.0.1:3306

at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {

errno: -111,

code: 'ECONNREFUSED',

syscall: 'connect',

address: '127.0.0.1',

port: 3306,

fatal: true

}

}

2021-06-09 19:19:44 error: connect ECONNREFUSED 127.0.0.1:3306

Cannot find module './'

Summary(์š”์•ฝ)

Getting error at npm start command

Additional Details(์ถ”๊ฐ€์ ์ธ ์„ธ๋ถ€ ์‚ฌํ•ญ)

  1. Project setup using command npx typescript-express-starter "project name"

  2. npm run start

Following error generated

`npx: installed 61 in 14.582s
Info: === tsc-alias starting ===
Info: 27 files were affected!
internal/modules/cjs/loader.js:638
throw err;
^

Error: Cannot find module './'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.Module._load (internal/modules/cjs/loader.js:562:25)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at Object. (D:\Paxcom\kinator-connector\dist\server.js:6:40)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: npm run build && cross-env NODE_ENV=production node dist/server.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.`

Jest unit test fails

Describe the Bug

yarn test or "npm run test" fails connect method of mongoose cannot be mocked.
As a result all of the test cases fail.

Version to Reproduce

Steps to Reproduce

npm install -g typescript-express-starter
npx typescript-express-starter nodeExpressTsSample
npm run test

Expected Behavior

The test cases should pass.

Actual Behavior

Test cases fail with error:
TypeError: Cannot read property 'then' of undefined
mongoose_1.connect(database_1.dbConnection.url, database_1.dbConnection.options)
.then(() => {
^
logger_1.logger.info('๐ŸŸข The database is connected.');

If applicable, add screenshots to help explain your problem. -->

Additional Context

Capture screen

image

Build fails when using TypeORM installation.

Describe the Bug(๋ฒ„๊ทธ ์„ค๋ช…)

After creating the project npx typescript-express-starter [project name] and running npm i. Running npm start builds the project, but when node tries to run the built output, it spits out this error.

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/chris/Projects/NodeAPI/node_modules/swagger-jsdoc/index.js
require() of ES modules is not supported.
require() of /Users/chris/Projects/NodeAPI/node_modules/swagger-jsdoc/index.js from /Users/chris/Projects/NodeAPI/build/app.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/chris/Projects/NodeAPI/node_modules/swagger-jsdoc/package.json.

Version to Reproduce(ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฒ„์ „)

This was running on a Mac using Node 14.15.5

Steps to Reproduce(์žฌํ˜„ ์ˆœ์„œ)

Expected Behavior(์˜ˆ์ƒ ๋™์ž‘)

I expect the project to build and run successfully even if it can't connect to a database or anything.

Actual Behavior(์‹ค์ œ ๋™์ž‘)

The error shown above.

ํ• ์ผ

.npmignore ๋กœ ๊นƒํ—ˆ๋ธŒ ํด๋” ์ •์˜
์ด๋ฏธ์ง€ ํŒŒ์ผ ๋ณ„๋„ ๋ ˆํฌ ์šด์˜
typescript ํด๋” ์ œ๊ฑฐ ๋ฐ ํ†ตํ•ฉ

Feature Request : Make Things Optional

We need a project that just works right after created. That helps to make trying things extremely easy and so attracts more people. That project fits me almost perfectly, no Passport things, creates auth and DB stuff, and so on. But, not including Pug is a minus.
I believe, if we can make these things optional we can put that project as an industry standard that helps people to code Node with TS.

New Feature Makefile

Motivation (์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ ์„ค๋ช…)

New Feature Makefile

docker build : https://docs.docker.com/engine/reference/commandline/build/

Proposed Solution (๊ธฐ๋Šฅ์„ ํ†ตํ•ด ์–ป๊ณ ์ž ํ•˜๋Š” ์†”๋ฃจ์…˜)

Build an image from a Dockerfile

Alternatives (์ œ์•ˆ ๋œ ์†”๋ฃจ์…˜์ด ๋” ๋‚˜์€ ์ด์œ )

Additional Context (์ถ”๊ฐ€ ์‚ฌํ•ญ)

Cannot see the actual error messages .

Describe the Bug(๋ฒ„๊ทธ ์„ค๋ช…)

The only error message received while running the project is :

[nodemon] app crashed - waiting for file changes before starting...

Version to Reproduce(ํ˜„์žฌ ์‚ฌ์šฉํ•œ ๋ฒ„์ „)

4.3.1

Steps to Reproduce(์žฌํ˜„ ์ˆœ์„œ)

  1. create default project using the cli
  2. Run : npm run dev , at this stage project runs fine.
  3. Create a typo in any .ts file for example: server.ts . Then save the file.
  4. [nodemon] app crashed - waiting for file changes before starting... , this error message is received.

This is a simple replication but not knowing what error occurred and where it occurred is really difficult to debug.

Expected Behavior(์˜ˆ์ƒ ๋™์ž‘)

The error messages should show the stack trace not just single line saying app has crashed.

    at Object.<anonymous> (/home/user/Documents/projects/node/typescript-express-starter/src/server.ts:12:13)
    at Module._compile (internal/modules/cjs/loader.js:1068:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:933:32)
    at Function.Module._load (internal/modules/cjs/loader.js:774:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47

Actual Behavior(์‹ค์ œ ๋™์ž‘)

Only this error message is displayed:

[nodemon] app crashed - waiting for file changes before starting...

Additional Context(์ถ”๊ฐ€ ์‚ฌํ•ญ)

node version:14.17.0
operating system: ubuntu 20.04

Capture screen(์บก์ณ ํ™”๋ฉด)

screen recording:
https://imgur.com/a/jEHKwAH

https://ibb.co/RBWdb9Y

Please acknowledge where you copied this project from

This exact line is from my readme in express-generator-typescript

"Node Js is great for the rapid development of web-projects, but is often neglected because of the lack of type safety. TypeScript solves this issue and (along with its linter file) can even make your code more robust than some other static languages like Java." Plus a huge chunk of other code is identical.

I know express-generator-typescript is an open source project but at least acknowledge your project as a fork/variation of mine you're going to copy me line-by-line.

getting error related to validationMiddleware

When I run server with default implementation, I get this:

TSError: โจฏ Unable to compile TypeScript:
src/middlewares/validation.middleware.ts:9:33 - error TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Request<ParamsDictionary, any, any, ParsedQs>'.
  No index signature with a parameter of type 'string' was found on type 'Request<ParamsDictionary, any, any, ParsedQs>'.

9     validate(plainToClass(type, req[value]), { skipMissingProperties })

How can I fix this?

NODE_ENV

์•ˆ๋…•ํ•˜์„ธ์š”.

app ์‹œ์ž‘์‹œ enum ํƒ€์ž…์˜ node_env ๋ฅผ ๊ฐ€์ง€๋ฉด ์ถ”ํ›„ ํ™œ์šฉํ•  ์ ์ด ์žˆ์„๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค~

enum NodeEnv {
  development = 'development',
  production = 'production',
}

Is the template following the clean architecute from R.C. Martin?

Summary(์š”์•ฝ)

Is the template following the clean architecture from R.C. Martin?

Additional Details(์ถ”๊ฐ€์ ์ธ ์„ธ๋ถ€ ์‚ฌํ•ญ)

the template project has a template like
/model ( or entities)
/service
/controller
/routes
pattern: https://github.com/ljlm0402/typescript-express-starter

But I have problems matching it to this architecture which many say is the de facto standard for a good software architecture

Like where do I find the entities, use cases, controllers etc.
For me only the controller layer is easy to find. In the template example project its also in the folder controllers.
In the example project the controllers use services and the services access the database.
If I try to map it to the pictures, use cases are the services and the entities are the models. But the models in the github project contain database specific code (for example typeorm notations).

grafik

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.