我有一个Node.js项目,我想知道如何使用'debugger;'。语句以暂停执行并检查堆栈跟踪以及Chrome中的变量状态。
这在我的其他其他使用React JS,Node和Express的项目中起作用。
当前的问题是调试器语句将被忽略,应用程序将继续运行而不停止。是否应该安装配置或库才能启用该功能?
package.json
{
"scripts": {
"ng": "ng",
"start": "node --inspect ./bin/www",
"debug-app": "node --inspect --debug-brk ./bin/www",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~7.1.0",
"@angular/common": "~7.1.0",
"@angular/compiler": "~7.1.0",
"@angular/core": "~7.1.0",
"@angular/forms": "~7.1.0",
"@angular/platform-browser": "~7.1.0",
"@angular/platform-browser-dynamic": "~7.1.0",
"@angular/router": "~7.1.0",
"bluebird": "^3.5.3",
"body-parser": "^1.18.3",
"bull": "^3.6.0",
"core-js": "^2.5.4",
"ejs": "^2.6.1",
"express": "^4.16.4",
"ioredis": "^4.5.1",
"mongo-express": "^0.51.1",
"mongoose": "^5.4.3",
"morgan": "^1.9.1",
"node-cron": "^2.0.3",
"node-fetch": "^2.3.0",
"rxjs": "~6.3.3",
"serve-favicon": "^2.5.0",
"swagger-ui-express": "^4.0.2",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.12.1",
"@angular/cli": "~7.1.4",
"@angular/compiler-cli": "~7.1.0",
"@angular/language-service": "~7.1.0",
"@babel/polyfill": "^7.2.5",
"@types/bull": "^3.5.5",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"nodemon": "^1.18.9",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.6"
}
}
bin / www
#!/usr/bin/env node
/**
* Module dependencies.
*/
require('babel-register')({
presets: ['env']
});
require("@babel/polyfill");
var app = require('../app');
var debug = require('debug')('mean-app:server');
var http = require('http');
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
/**
* Create HTTP server.
*/
var server = http.createServer(app);
/**
* Listen on provided port, on all network interfaces.
*/
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val)
{
var port = parseInt(val, 10);
if (isNaN(port))
{
// named pipe
return val;
}
if (port >= 0)
{
// port number
return port;
}
return false;
}
/**
* Event listener for HTTP server "error" event.
*/
function onError(error)
{
if (error.syscall !== 'listen')
{
throw error;
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;
// handle specific listen errors with friendly messages
switch (error.code)
{
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening()
{
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}