[英]Does anyone know how to run the script in the .json file automatically everytime I open my index.html page?
.json 文件中有一個腳本部分,每次如果我想運行我的 html 頁面(在服務器上),我需要通過在終端中鍵入npm run (the script's name)
我想知道如何通過打開我的 index.html 來自動運行它。
該腳本旨在從命令行運行。
如果您想更改它以使其響應正在加載的網頁而運行:
例如
const yourscript = require("./yourscript.js");
app.get('/', (req, res) => {
yourscript();
res.render('index')
})
(不是一個詳盡的例子,請閱讀 Express.js 文檔)
並確保通過從網絡服務器請求它來加載網頁(例如http://localhost:3000/
並且不直接從文件系統訪問文件)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.