1
0

More than 3 years have passed since last update.

WEBフレームワーク「express」について

Last updated at Posted at 2021-06-24

expressとは

サーバサイドのWEBアプリケーションフレームワークである。
Node.jsで作成する。
必要最小限の機能しかないため、その他ミドルウェアと組み合わせて使用する。

expressでできること

  • ルーティング
  • リクエスト整形

expressではできないこと

  • リクエスト分析
  • 認証認可
  • DB接続

expressを補うミドルウェアの例

  • リクエスト分析: body-parser
  • セッション管理:express-session
  • 認証:passport

expressでWEBアプリケーションサーバを作成

express環境構築

npm init

init実行後の設定項目
スクリーンショット 2021-06-24 14.44.47.png

npm install express --save

app.jsファイルを作成

app.js
var express = require("express"),
    app = express();

app.get("/", (req, res) => {
  res.status(200).send("Hello ,world.");
});

app.listen(3000);

ファイルを実行する。

node app.js

実行後、ブラウザを立ち上げて下記へアクセスする。

下記画面が出てくればOK
スクリーンショット 2021-06-24 14.55.31.png

以上。

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