LoginSignup
4
2

More than 5 years have passed since last update.

最近のNode.jsプロジェクトのだいたいテンプレ

Last updated at Posted at 2018-10-26

サンプルプロジェクト

要素

  • Typescript
  • ts-node
  • koajs
  • koa-router
  • tslint (standard)
  • mocha, chai
  • log4js
  • config

説明

TypeScriptで書いて、tscはせずにts-nodeでそのまま動かしている。
ts-nodeだとサーバーなどは起動頻度が低くていいけど、コマンド実行系が遅くてめんどくさいのでtscするように変更。

Webまわりはkoajsを使っている。expressに差し替えても問題ない。
tslintはtslint-config-standardを使っているけどこのへんは好み。
DBは含めてないが、mongooseやsequelizeなどその都度好きなのを使う。

index.tsserver.tsを分けているのはAPIのテストを
走らせるため。

const server = new http.Server(app.callback())

いったん上記のようにhttpをはさんでいるのはsocket.ioなどを使うときのため。

Docker使わないときのサーバー上での起動はpm2を使っていて、デプロイもpm2 deployを使っている。
サーバー側のpm2のセットアップは

npm i -g pm2
pm2 install typescript

としておく。
pm2のconfigはecosystem.config.jsのように書く。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2