1. インストール
node.js は、インストール済みとします。
コマンドプロンプトで、同じディレクトリで以下を実行しました
>npm init
(聞かれるパラメータは、すべて適当に答える)
>npm install express
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN togis@1.0.0 No description
npm WARN togis@1.0.0 No repository field.
と怒られる
しょうがないので、gitのリポジトリを適当につくる
>git init
>git add package-lock.json
>git commit
おこられるが、無視
再び
>npm install express
ワーニングがでるけど、node_modulesフォルダもあるので、
できてるのかなと思う
2.サンプル
次のようなコードを作成します(index.js)
const express = require('express')const app = express()app.get('/', (req,res) => res.send('Hello'))app.listen(3000, () => console.log('running'))
3.実行結果
1.をインストールしたフォルダーにて
コマンドプロンプトで
>node index.js
を実行すると、コマンドプロンプトに
running
が表示されます
ブラウザで
http://localhost:3000/
を指定すると
Hello
が表示されました。
0 件のコメント:
コメントを投稿