Visual Studio Code express app
See original GitHub issueI am trying to run an express app through Visual Studio Code. I have a launch.json file with DEBUG defined like so:
"env": {
"DEBUG": "*"
}
Here is a trimmed down version of my app.js file where you can see the bolded debug line that doesn’t output to the debug console (Test 2). Test 1 before it outputs as expected. If I run this from the command line passing DEBUG=* npm start
both lines show as expected.
var debug = require('debug')('app');
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const app = express();
const v1 = require('./routes/v1');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
**debug("Test 1 that outputs!");**
app.use(function(req, res, next) {
console.error("THIS OUTPUTS");
**debug("Test 2 that doesn't output!!");**
console.log(`${req.method} request for '${req.url}' - ${JSON.stringify(req.body)}`);
next();
});
app.use(cors());
app.listen(3000);
console.log("Service running on port 3000");
module.exports = app;
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (3 by maintainers)
Top Results From Across the Web
Build Node.js Apps with Visual Studio Code
The Visual Studio Code editor has great support for writing and debugging Node.js applications. This tutorial takes you from Hello World to a...
Read more >Tutorial: Create a Node.js and Express app in Visual Studio
In this tutorial, learn how to create a basic Node.js application by using the Express web application framework in Visual Studio.
Read more >How to create and run Node.js project in VS code editor
Step 1: Create an empty folder and move it into that folder from your VS Code editor, use the following command. ; Step...
Read more >A Practical Introduction to Setting Up a NodeJs+Express web ...
In your VSCode, Open the MyNodeJsProject folder . You can open the folder by clicking the file tab located at the upper...
Read more >Node.js Applications with VS Code - vscode-docs
Express is a very popular application framework for building and running Node applications. You can scaffold a new Express application using the Express...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Or you can keep
"outputCapture": "console"
and add the following (before requiring debug) to trigger the browser logger:Would love a toggle switch like
debug.forceConsoleLogging = true
. Or if anyone wants to automate it I would suggest this implementation from Node’s Cluster module: https://github.com/nodejs/node/blob/422e8f762873aef4a37185f3237c0d666c929d8e/lib/internal/cluster/master.js#L103-L109@michielbdejong the debug socket is the
ws://127.0.0.1:45341/f8704798-75c0-4c1c-9086-7a3c1d483cf3
which you can see in the beginning of my debug console above. VS Code and Node communicate through this socket using Chrome Debugging Protocol to transfer console.logs, console.errors… (no stdout/stderr), and also stack trace info (browser.js:183
on the right), breakpoint control and so on. I believe that by attaching to it you won’t be able to solve the issue, because you would be a client and the server (Node) is what emits the console, not sure.In case anyone is using TypeScript, here’s the type declarations:
Just found out that there is an inspector module built in to node which allows you to transfer information to the debug console. So I guess it could actually be easily implemented by adding
inspector.console.log
call after theprocess.stdout.write
call, the only issue would be coloring.Thanks for the report and the detailed information. It’s refreshing to be able to reproduce something so quickly 😄
You’re absolutely right. For some bizarre reason, VSCode patches
console
when they should really be consuming stdout/stderr streams - or both, I suppose.See https://github.com/Microsoft/vscode/issues/19750#issuecomment-344037380 - it doesn’t appear to be something they want to fix concretely.
Add this to your
launch.json
:(by default, it’s
"console"
, butdebug
usesprocess.stderr.write()
- appropriately, I might add).Thanks again for reporting.
I would happily accept a PR for adding this piece of information into the README 😃