0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Express勉強

Posted at

メモ

expressでappを作成するうえでMVCモデルのひな型を作ってくれるツールがExpress Application Generator ツール。

npm install express-generator

パッケージをインストールしてひな型を作っていく。

express express-locallibrary-tutorial --view=pug

expressコマンドで第一引数にapp名、第二にテンプレートエンジンを指定。

テンプレートエンジンとはwebテンプレート(テンプレート言語が埋め込まれている HTML)とデータモデル(DBから取り出したデータ)から

htmlドキュメントを生み出すソフト。

これがないとdjangoだけでappサーバとして動いたりできない。

バックをapi実装するだけならばいらない、、かな

https://pyteyon.hatenablog.com/entry/2019/08/23/135834

するとapp名のフォルダができてその中にいろいろな機能をもったフォルダが作成されている。

package.jsonにインストールしなければいけないパッケージ一覧が書かれているのでインストールする。

npm install

package.jsonが存在するディレクトリでコマンドを打てば、package.jsonに記述されている依存パッケージを自動でインストールしてくれる。

アプリの実行

 DEBUG=express-locallibrary-tutorial:*  npm start

node.jsはシングルスレッド。シングルスレッドとは並列処理と逆の意味で、「逐次処理」。

しかし並列処理できたほうが良いように思う。アクセスが多くなるとその分プロセスが生まれるApacheのように。

しかしアクセスが多くなると重くなる。C10K問題。

なので、シングルプロセスシングルスレッド。しかしそれだけでは一つの処理の間待っておかなければいけないので、効率が悪い。

そこで非同期IO。これは一つの処理を行っている裏で異なる処理を行う、そして処理が終わったら教えてもらう。

これにより、処理を同時並行で行える。nginxは非同期。

node.jsはシングルスレッドで非同期IO。

https://knowledge.sakura.ad.jp/24148/#C10K

https://tamotech.blog/2020/07/15/node-single-thread/

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?