創建node服務器
1、在項目路徑下,新建server文件夾和dist文件夾,在server文件夾下新建index.js文件
2、先npm安裝express
3、在index.js文件中,輸入代碼,創建node服務器
// node 後端服務器
const express = require('express');
const app = express();
app.use(express.static('../dist')); //指定靜態資源文件目錄
var server = require('http').createServer(app);
// 監聽端口
server.listen(3000);
console.log('success listen at port:3000......');
4、在server目錄,打開命令窗口,輸入
node index
5、在dist目錄下,新建一個index.html,(dist是存放打包後的內容的,暫時先使用index.html進行測試)
6、打開瀏覽器,輸入 http://localhost:3000/ ,可以看到index.html中的內容