The problem with the cluster on Visual Studio code (F5) on Node.js v6.0.0

I have a problem with Visual Studio code with Cluster

Edit

If I pressed Ctrl + F5 , it works correctly, what does it do other than just F5 , do I always need to run the command with Ctrl?

---

It seems that workers never start at startup using the VS Code Launch (F5) command . Do I need to make some changes to the .vscode / launch.json file in order to make the cluster work by working out.

The actual code is copied from Node.js 6 api https://nodejs.org/api/cluster.html#cluster_cluster

npm test . The Windows command line shows the following:

Master started
Listening port 80
Listening port 80
Listening port 80
Listening port 80

VS (F5) :

node --debug-brk=7601 --nolazy index.js
Debugger listening on port 7601
Master started
Debugger listening on port 7602
Debugger listening on port 7603
Debugger listening on port 7604
Debugger listening on port 7605

VS Code launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/index.js",
            "stopOnEntry": false,
            "args": [],
            "cwd": "${workspaceRoot}",

    ..........

index.js

const cluster = require('cluster');
const http = require('http');
const numCPUs = require('os').cpus().length;

if (cluster.isMaster) {
    // Fork workers.
    console.log('Master started')
    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }

    cluster.on('exit', (worker, code, signal) => {
        console.log(`worker ${worker.process.pid} died`);
    });
} else {
    // Workers can share any TCP connection
    // In this case it is an HTTP server
    http.createServer((req, res) => {
        res.writeHead(200);
        res.end('hello world\n');
    }).listen(80);
    console.log('Listening port 80')
}
+4
2

. , weinand https://github.com/Microsoft/vscode/issues/3201, :

node VS .

: node --debug app.js

"attach" .

, .

+1

Visual Studio .

, , .

Mac OS X:

//Visual Studio Code.app/Contents/Resources/app/extensions/ node -debug//node/nodeDebug.js

:

C:\Program Files (x86)\Microsoft VS Code\resources\app\extensions\ node -debug\out\node\nodeDebug.js

if (!this._noDebug) {
    launchArgs.push("--debug-brk=" + port);
}

to

if (!this._noDebug) {
    launchArgs.push("--debug=" + port);
}

, , .

0

All Articles