From f73690682ed62dec21cd808a077fd61cdc12ce98 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Thu, 20 Jun 2019 04:50:28 +0100 Subject: [PATCH] fix: better debugging experience with cluster (#2447) --- docs/en/joinus/README.md | 43 ++++++++++++++++++++++++++++++++++++++++ docs/joinus/README.md | 43 ++++++++++++++++++++++++++++++++++++++++ lib/index.js | 2 +- package.json | 4 ++-- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/docs/en/joinus/README.md b/docs/en/joinus/README.md index 01c4e3486..14fceb379 100644 --- a/docs/en/joinus/README.md +++ b/docs/en/joinus/README.md @@ -474,3 +474,46 @@ Add the script into [/lib/router.js](https://github.com/DIYgod/RSSHub/blob/maste 1. [Telegram Group](https://t.me/rsshub) 2. [GitHub Issues](https://github.com/DIYgod/RSSHub/issues) + +## Some Tips for Development + +### VS Code debug configuration + +`.vscode/launch.js` + +#### Debugging with nodemon + +In terminal, run `npm run dev` or `yarn dev` to start debugging. + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", + "name": "Node: Nodemon", + "processId": "${command:PickProcess}", + "restart": true, + "protocol": "inspector" + } + ] +} +``` + +#### Debugging without nodemon + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/lib/index.js", + "env": { "NODE_ENV": "dev" } + } + ] +} +``` diff --git a/docs/joinus/README.md b/docs/joinus/README.md index 955f1344f..10ab8cf94 100644 --- a/docs/joinus/README.md +++ b/docs/joinus/README.md @@ -488,3 +488,46 @@ ctx.state.data = { 1. 请一定要注意把``的标签关闭! 1. 执行 `npm run format` 自动标准化代码格式,提交代码, 然后提交 pull request + +## 一些开发 tips + +### VS Code 调试配置 + +`.vscode/launch.js` + +#### 使用 nodemon 调试 + +在终端使用 `npm run dev` 或 `yarn dev` 开始调试。 + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "attach", + "name": "Node: Nodemon", + "processId": "${command:PickProcess}", + "restart": true, + "protocol": "inspector" + } + ] +} +``` + +#### 不使用 nodemon 调试 + +```json +{ + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/lib/index.js", + "env": { "NODE_ENV": "dev" } + } + ] +} +``` diff --git a/lib/index.js b/lib/index.js index 510bc09e4..0078ac36e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -28,7 +28,7 @@ const apiResponseHandler = require('./middleware/api-response-handler'); const cluster = require('cluster'); const numCPUs = require('os').cpus().length; -if (cluster.isMaster && !config.disableCluster && process.env.NODE_ENV !== 'test') { +if (cluster.isMaster && !config.disableCluster && process.env.NODE_ENV !== 'test' && process.env.NODE_ENV !== 'dev') { for (let i = 0; i < numCPUs; i++) { cluster.fork(); } diff --git a/package.json b/package.json index 4ade525ec..6771f8928 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "scripts": { "start": "node lib/index.js", - "dev": "nodemon $NODE_DEBUG_OPTION lib/index.js", + "dev": "NODE_ENV=dev nodemon --inspect lib/index.js", "docs:dev": "vuepress dev docs", "docs:build": "vuepress build docs", "format": "eslint \"**/*.js\" --fix && node docs/format.js && prettier \"**/*.{js,json,md}\" --write", @@ -118,4 +118,4 @@ "_moduleAliases": { "@": "./lib" } -} +} \ No newline at end of file