Meanjs-building-static-route-node-express

提供:Dev Guides
移動先:案内検索

MEAN.JS-静的ルートノードエクスプレスの構築

この章では、 Node および Express を使用したアプリケーションのルートの構築について説明します。

前の章では、node-expressアプリケーションを作成しました。 _mean-demo_というプロジェクトディレクトリに移動します。 以下のコマンドを使用してディレクトリに移動します-

$ cd mean-demo

ルートを設定する

ルートは、着信要求のURLを使用して、マッピングサービスとして使用されます。 server.js ファイルを開き、以下に示すようにルーティングを設定します-

//modules =================================================
const express = require('express');
const app = express();

//set our port
const port = 3000;
app.get('/', (req, res) ⇒ res.send('Welcome to finddevguides!'));

//defining route
app.get('/tproute', function (req, res) {
   res.send('This is routing for the application developed using Node and Express...');
});

//startup our app at http://localhost:3000
app.listen(port, () ⇒ console.log(`Example app listening on port ${port}!`));

実行中のアプリケーション

次に、以下のコマンドでアプリケーションを実行します-

$ npm start

以下の画像に示すように、確認が得られます-

実行中のアプリケーション

ここで、ブラウザに移動して http://localhost:3000/myroute と入力します。 あなたは、以下の画像に示すようにページを取得します-

Node Express