如何 运行 一个带有附加环境变量 Debug=* in VSCode in Node.js 的脚本?

How to run a script with additional environment variable Debug=* in VSCode in Node.js?

这是我的代码:

const CrawlE = require('crawl-e/v0.5.2')
const debug = require('debug')


let crawlE = new CrawlE({
  cinemas: [
    {
      name: 'Kino Gmunden',
      address: 'Theatergasse 7, 4810 Gmunden',
      website: 'http://www.kino-gmunden.at/',
      phone: '0676 / 88 794 505'
    }
  ],

  showtimes: {
    url: 'https://www.daskino.at/programm/',
  }
  
})

crawlE.crawl()

我想添加一个环境变量 Debug=*,我该如何设置它并用它制作这个脚本 运行?

如果您是 运行 您的命令行脚本,只需在 运行 脚本

之前设置环境变量
// command line
DEBUG=* node index.js

// package.json
"scripts": {
  "test": "DEBUG=* node index.js"
},

// example vscode launch configuration
{
  "type": "node",
  "request": "launch",
  "env": { "DEBUG": "*" }, // -> this is the important part!
  "name": "Main",
  "program": "${workspaceFolder}/src/index.js",
  "skipFiles": [
    "${workspaceFolder}/node_modules/**/*.js",
    "<node_internals>/**/*.js"
  ]
},