1.Node.jsをインストールする
インストールされてからかなり時間が経っているので、自分では書きません。以下のリンクが非常に詳しく説明されています。
インストールチュートリアル
2.Expressをインストールする
- VSCode でプロジェクト フォルダーを開き、ターミナルを開きます。
- ターミナルを入力します
npm i express
。
このインストールでは次の問題が発生します。
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
3.エクスプレス利用
コードは以下のように表示されます。
//1.引入express
const express=require('express');
//2.创建应用对象
const app=express();
//3.创建路由规则
//request是对请求报文的封装
//response是对响应报文的封装
app.get('/',(resquest,response)=>{
response.send('hello');
})
//4.监听端口
app.listen(8000,()=>{
console.log("qidong");
})
VSCode がサービスを開始します。
- まずターミナルでパスを開きます。
- 「ターミナル」と入力します
node 文件名.js
。 - ブラウザに入力してください
127.0.0.1:8000
。