簡體   English   中英

當我在我的前端 - Angular 上進行更改時,如何在 nodeJs 中自動啟動和重新加載 index.js?

[英]How can I automatic start and reload index.js in nodeJs, when I do changes on my frontend - Angular?

我知道,我必須更改我的 package.json 文件,但我不明白如何。 我嘗試在 package.json 腳本中使用“手表”,但它沒有用。 請幫我。 我剛開始學習 Angular 和 NodeJs。 對不起我的英語不好和簡單的問題。 現在我總是用 nodemon index.js 重新加載我的服務器並且有問題:在此處輸入圖像描述

  "dependencies": {
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "express": "^4.17.1",
    "mysql2": "^2.3.3",
    "node": "^17.1.0"
  },
  "name": "server",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "devDependencies": {
    "nodemon": "^2.0.15"
  }
}

我相信您在src文件夾中有index.js

使用環境設置

  .
  . 
  "scripts": {
    "start": "node src/index.js",
    "dev": "***env-cmd -f ./config/dev.env*** nodemon src/index.js",
    "test": "env-cmd -f ./config/test.env jest --watch"
  },
 .
 .

沒有 Environment並且想要跟蹤js以外的文件擴展名的更改。

如果要在js, hbs, html文件更改上自動啟動服務器。

  .
  . 
  "scripts": {
    "start": "node src/index.js",
    "dev": "env-cmd -f ./config/dev.env nodemon src/index.js -e js,hbs,html",
    "test": "env-cmd -f ./config/test.env jest --watch"
  },
 .
 .

沒有環境並且只跟蹤js文件

以下部分顯示了沒有環境設置的命令。 在這里,我們完全忽略了-e參數,因為我們不想在.js以外的文件發生更改時自動啟動服務器。

  .
  . 
  "scripts": {
    "start": "node src/index.js",
    "dev": "nodemon src/index.js",
    "test": "env-cmd -f ./config/test.env jest --watch"
  },
 .
 .

在命令提示符下。 運行以下命令:

$npm run dev

注意: -您可以忽略上述解決方案中的starttest

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM