0.5.0 • Published 7 years ago

node-devtools v0.5.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

node-devtools

This package(built on electron), aims to run and debug node.js program with Chrome DevTools.

Imagine a javascript file named demo.js:

console.log(require('http'));

All you need to do is to open a command line and type:

$ node-devtools demo.js

Then Chrome DevTools will be presented to you:

demo

When you did some modifications and need to reload current script, press ctrl+r or F5.

Install

With npm:

$ npm install node-devtools -g

Usage

The usage is highly consistent with node:

$ node-devtools [options] [v8 options] [entry script] [arguments]

You can execute without entry script and arguments to start the REPL.

Options

-v, --version

Print versions of node-devtools and its underlying tools.

-e, --electron

Node-devtools will download and use the latest version of electron automatically. If you want to use a different one, you should download it and specify the filename of your electron binary file by this option.

-w, --watch

Watch file or directory, auto reload current script when they have changed, default is 0.

  • 0: do not watch.
  • 1: watch the entry file.
  • 2: watch the directory(and all its subdirectories)of the entry file.
  • a string: specify a file or directory to be watched.

-c, --context

Specify the context in which your script is going to be executed, default is "module".

  • module: your script will be loaded as the main module.
  • global: your script will be executed in the global scope.

-r, --reserve

By default, node-devtools will try to remove all global variables which only exists on browser side, you can use -r flag to reserve them.

You can also reserve some of them, separate them by spaces like node-devtools --reserve="alert confirm" index.js.

Notice window, document, location, top, caches are read-only and non-configurable, these global variables cannot be removed.

V8 options

Add v8 flags as you do with node, for example, node-devtools --harmony index.js.

An unofficial, community-maintained list of options and their effects is available here.

Caveat

Because the process was created by electron instead of node, some properties of process may be different. For example, process.title, process.argv0, process.release, process.versions.

Specifically, process.argv, process.execArgv and process.execPath have no difference from using node:

$ node-devtools --watch=1 --harmony test.js arg1 arg2
// test.js
console.log(process.argv); // ['path/to/node', 'path/to/test.js', 'arg1', 'arg2']
console.log(process.execArgv); // ['--watch=1', '--harmony']
console.log(process.execPath); // path/to/node

If your code is running with node-devtools, process._devtools will be true, this can be useful in some cases:

if (process._devtools) console.profile('test');
doSomeThings();
if (process._devtools) console.profileEnd('test');
0.5.0

7 years ago

0.4.0

7 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.0

8 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.0.1

8 years ago