简体   繁体   中英

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

this is my code:

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()

i want to add an environment variable Debug=*, how can i set it and make this script run with it?

If you are running your script from the command line just set the environment variable before running the script

// 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"
  ]
},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM