新增專案
在專案目錄中, 執行以下指令來初始化專案:
mkdir QL
cd QL
npm init -y
安裝 Express.js
npm install express
建立測試內容(app.js):
const express = require('express');
const app = express();
const port = 3000;
// 建立一個簡單的路由
app.get('/', (req, res) => {
res.send('Hello, Express.js on local server!');
});
// 啟動伺服器
app.listen(port, () => {
console.log(`Express app is running at https://localhost:${port}`);
});
安裝 Express.js
npm install express
建立測試內容(app.js):
const express = require('express');
const app = express();
const port = 3000;
// 建立一個簡單的路由
app.get('/', (req, res) => {
res.send('Hello, Express.js on local server!');
});
// 啟動伺服器
app.listen(port, () => {
console.log(`Express app is running at https://localhost:${port}`);
});
// 測試
node app.js
// 檔案變更時, 伺服器自動重新啟動
npm install -g nodemon
nodemon app.js