内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list($forumlist, $model = 0, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $model . '-' . $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 不分模型 * @param int $display 0全部CMS栏目 1在首页和频道显示内容的栏目 * @param int $category 0列表 1频道 2单页 3外链 * @return array */ function category_list_show($forumlist, $display = 0, $category = 0) { if (empty($forumlist)) return NULL; static $cache = array(); $key = $display . '-' . $category; if (isset($cache[$key])) return $cache[$key]; if ($display) { foreach ($forumlist as $k => $val) { if (1 == $val['display'] && 1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } else { foreach ($forumlist as $k => $val) { if (1 == $val['type'] && $val['category'] == $category) { $cache[$key][$k] = $val; } } } return empty($cache[$key]) ? NULL : $cache[$key]; } /** * @param $forumlist 所有版块列表 * @return mixed BBS栏目数据(仅列表) 尚未开放bbs频道功能 */ function forum_list($forumlist) { if (empty($forumlist)) return array(); static $cache = array(); if (isset($cache['bbs_forum_list'])) return $cache['bbs_forum_list']; $cache['bbs_forum_list'] = array(); foreach ($forumlist as $_fid => $_forum) { if ($_forum['type']) continue; $cache['bbs_forum_list'][$_fid] = $_forum; } return $cache['bbs_forum_list']; } // 导航显示的版块 function nav_list($forumlist) { if (empty($forumlist)) return NULL; static $cache = array(); if (isset($cache['nav_list'])) return $cache['nav_list']; foreach ($forumlist as $fid => $forum) { if (0 == $forum['nav_display']) { unset($forumlist[$fid]); } } return $cache['nav_list'] = $forumlist; } ?>javascript - Debugging local nodejs script in chrome dev tools - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Debugging local nodejs script in chrome dev tools - Stack Overflow

programmeradmin0浏览0评论

I have a stand alone node js script. I am doing some local task with that script. I want to debug that script in chrome dev tools. I know I can debug it locally via putting debugger in code but do not want to do that.

On nodejs docs I saw that it has some options like -

V8 Inspector Integration for Node.js# NOTE: This is an experimental feature.

V8 Inspector integration allows attaching Chrome DevTools to Node.js instances for debugging and profiling.

V8 Inspector can be enabled by passing the --inspect flag when starting a Node.js application. It is also possible to supply a custom port with that flag, e.g. --inspect=9222 will accept DevTools connections on port 9222.

To break on the first line of the application code, provide the --debug-brk flag in addition to --inspect.

$ node --inspect index.js

But when I do that it gives me error like -

$ node --inspect index.js
node: bad option: --inspect

My node version is:

$ node --version
v4.4.7

I have a stand alone node js script. I am doing some local task with that script. I want to debug that script in chrome dev tools. I know I can debug it locally via putting debugger in code but do not want to do that.

On nodejs docs I saw that it has some options like -

V8 Inspector Integration for Node.js# NOTE: This is an experimental feature.

V8 Inspector integration allows attaching Chrome DevTools to Node.js instances for debugging and profiling.

V8 Inspector can be enabled by passing the --inspect flag when starting a Node.js application. It is also possible to supply a custom port with that flag, e.g. --inspect=9222 will accept DevTools connections on port 9222.

To break on the first line of the application code, provide the --debug-brk flag in addition to --inspect.

$ node --inspect index.js

But when I do that it gives me error like -

$ node --inspect index.js
node: bad option: --inspect

My node version is:

$ node --version
v4.4.7
Share Improve this question asked Nov 11, 2016 at 15:14 WitVaultWitVault 24.1k20 gold badges106 silver badges137 bronze badges 3
  • 1 Node 4 didn't have this experimental feature. It appeared in node 6. Probably you were reading latest docs. This one is for node 4: nodejs/dist/latest-v4.x/docs/api/debugger.html – Andrey Commented Nov 11, 2016 at 15:30
  • If you're running node.js v4 then node-inspector is worth a look – dan Commented Nov 11, 2016 at 15:38
  • A related post here related to development/debugging in NodeJs. – RBT Commented Jan 25, 2018 at 6:38
Add a ment  | 

3 Answers 3

Reset to default 8

You need node 6.3 or above --inspect is not supported in 4.4.7

@Andrey Thanks a lot for pointing out that I was scratching my head for a long time on this. @dan Thanks for node-inspector suggestion.

I am just posting an answer in case someone else might stuck on this.

I have installed node-inspector and,

This is what I'm doing to start the debugger.. Opened one terminal and

$ node-inspector --no-preload
Node Inspector v0.12.5
Visit http://127.0.0.1:8080/?ws=127.0.0.1:8080&port=5858 to start debugging.

In another terminal,

$ node --debug-brk app.js 
debugger listening on port 5858

Intially I was using just --debug. But it was not hitting the breakpoints and was going through all code. Then I used --debug-brk. Using --debug-brk caused node to break on the first line of app and waited for a debugger to hit breakpoints.

Then started Google Chrome and went to http://127.0.0.1:8080/debug?port=5858

Here chrome dev tools was opened and I was able to put break point and debug the code.

Node Inspector works pretty well. Also keep in mind Node 7 has native node debugging, even supports live-edit! Here's a gif of it in action: Chrome DevTools: Live edit running Node.js code with hotswapping

发布评论

评论列表(0)

  1. 暂无评论