Giter Club home page Giter Club logo

nest-api's Introduction

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.

nest-api's People

Contributors

masapon06 avatar

Watchers

 avatar

nest-api's Issues

prettierで改行した関数のチェーンが一列になる

概要

prettierでコード成形時、改行したチェーンが平らに均される。

  • 書いたコード
const bar = await this.barModel
.findById(param.id)
.populate('comments')
.lean()

  • 整形後
const bar = await this.barModel.findById(param.id).populate('comments').lean()

リポジトリ運用

commit の命名

  • fix:バグ修正
  • add:新規(ファイル)機能追加
  • update:機能修正(バグではない)
  • remove:削除(ファイル)

→参考

テスト書く

概要

  • 現状実装されているbar, commentの自動テスト導入
  • テストコード書く

書いたテスト

  • bars-controller
    • findAll
    • findById
    • create

/barsエンドポイントにGETメソッドでリクエストを投げるとエラーを吐く

内容

現在のmasterブランチで/barsエンドポイントにGETメソッドでリクエストを投げると、以下のようなエラーを吐く。

/Users/username/nest-api/node_modules/express/lib/response.js:766
        var charset = mime.charsets.lookup(value.split(';')[0]);
                                    ^
TypeError: Cannot read property 'lookup' of undefined
    at ServerResponse.header (/Users/username/nest-api/node_modules/express/lib/response.js:766:37)
    at ServerResponse.json (/Users/username/nest-api/node_modules/express/lib/response.js:264:10)
    at ExpressAdapter.reply (/Users/username/nest-api/node_modules/@nestjs/platform-express/adapters/express-adapter.js:29:57)
    at ExceptionsHandler.handleUnknownError (/Users/username/nest-api/node_modules/@nestjs/core/exceptions/base-exception-filter.js:38:24)
    at ExceptionsHandler.catch (/Users/username/nest-api/node_modules/@nestjs/core/exceptions/base-exception-filter.js:17:25)
    at ExceptionsHandler.next (/Users/username/nest-api/node_modules/@nestjs/core/exceptions/exceptions-handler.js:16:20)
    at /Users/username/nest-api/node_modules/@nestjs/core/router/router-proxy.js:13:35
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

考えられる原因

  • serviceではmongoからpopulateしたデータを取得できることをログで確認しているため、mongo関連ではない。
  • controllerでのnestのメソッドの使い方がよくない?
  • もしくはなにか依存関係に問題がある?express, mineとエラーに出てる。
    • エラーで調べたところバージョンを更新しろ系の記事が多い。

テスト用のmemory-serverの導入

内容

  • jestのmock()だとモックができない
    • createはdtoとschemaのデータの型が異なるので不可
    • findByIdは_idがschemaで定義されておらずmongoの自動生成のため不可. ObjectIdを生成するメソッドもあるが型が合わない
      • →解決。stubを新たに作成して対応
  • mongo-memory-serverを導入する

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.