nodelive
Dynamic interaction within nodejs programs.
Install
$ npm i -D nodelive
Why?
To inject code in live node executions.
To not have to open Chrome to debug nodejs.
To debug, in live, from the inside, with some tools already.
To hack other programs easily too, why not.
Features
- [✔] Live code injection and exploration.
- [✔] Memory usage printing.
- [✔] Advanced printing for debugging.
- [✔] Functions source code.
- [✔] Circular JSON structures.
- [✔] Easy command line interface input for:
- [✔] Text
- [✔] Confirm
- [✔] Options
Get started
This package consists in 1 unique object that exposes the whole API.
To import it:
const nodelive = ;
Demo
You will find examples of the usable API for the next topics:
- [✔] For general help
- [✔] For console
- [✔] For editor
For general help
Store and retrieve values from nodelive (a simple helper storage).
nodelive;nodelive; // >> "b"nodelive; // >> {a:"a",b:"b",c:"c"}
Stringify (supports circular JSON).
nodelive;
Print message.
nodelive;
Explore any type of data.
nodelive;
List all properties of an object.
nodelivedescriptionglobal;
Print the description of an object.
nodelive;
Stringify and print data.
nodelive;
Show memory usage.
nodelive;
For console
Execute command for the native console synchronously
nodelive
Ask for user input (as string).
const name = await nodelive;
Ask for user input (as boolean).
const isBusy = await nodelive;
Ask for user input, as options election (of strings).
const optionSelected = await nodelive;
Enter into a command-line loop to inject code!
await nodelivecode
Evaluate specific expression from console!
await nodelive
For editors
Open editor and inject code in live!
const parameterNames = "name" "age";const parameters = "Carlos" "50"; nodelivePREFERRED_EDITOR = "brackets"; // By default it is "subl" of Sublime Text! await nodelive;
To see some more examples, please go to the tests folder of the project at Github.
API
Here you can have an overview of the whole API.
Note: all the code injections support await
expressions by default.
nodelive.get(name:String)
Gets a value from the nodelive internal memory.
nodelive.set(name:String, value:any)
Saves a value in the nodelive internal memory.
Chainable method.
nodelive.put(Object:values)
Saves a set of key-value pairs in the nodelive internal memory.
Chainable method.
nodelive.stringify(...args)
Returns a JSON representation, no matter about circular JSON or functions.
nodelive.print(...data)
Prints the data by console.
Chainable method.
nodelive.explore(...data)
A more exhaustive printing of objects, functions, etc.
Chainable method.
nodelive.description(data:any)
Returns a deep description of all the properties of an object. The description contains the index (sorted alphabetically), the type of property and the property name.
nodelive.describe(data:any)
Prints the description extracted of the passed object.
Chainable method.
nodelive.view(data:any)
Stringifies and prints any data.
Chainable method.
nodelive.memory()
Prints a memory usage summary.
Chainable method.
nodelive.cmd(command:String, options:Object)
Synchronous. Execute command-line commands in a nut.
nodelive.ask(message:String): Promise<String>
Asynchronous. Prints a question. Returns an answer as string.
nodelive.askif(message:String, defaultValue:boolean): Promise<Boolean>
Asynchronous. Prints a question. Returns an answer as boolean. By default, the answer is false.
nodelive.askone(options:Array<String>, message:String): Promise<String>
Asynchronous. Prints a question and a numbered list. Returns the value selected from the list as string.
nodelive.code(message:String): Promise
Asynchronous. Inject (multiline) code in live.
To get out, you must enter an empty line.
nodelive.evaluate(message:String): Promise
Asynchronous. Evaluate js expressions (one line, something) of code in live.
nodelive.live(message:String): Promise
Asynchronous. Inject (multiline) code in loop (so, a simple REPL) until you return "exit" (as a string).
To get out, you must return 'exit'
.
nodelive.inspect(message:String): Promise
Asynchronous. Explore the data that nodelive
has saved in memory (from selector).
nodelive.executeCode(code:String, isMultiline:Boolean, ok:Function, fail:Function)
Asynchronous callback. Executes js
code, embeded in async
environment already.
Under the hood, code
, evaluate
, live
and editor
functions use this method to inject code
and output a standard response.
nodelive.editor(argsNames:Array<String>, args:Array<any>): Promise
Asynchronous. Opens a file on your preferred editor (set it at nodelive.PREFERRED_EDITOR
)
that when saved, it is injected.
It has the ability to pass parameters and rename them, for your code to receive them.
To get out, save an empty text.
nodelive.editor(args:Object): Promise
Asynchronous. Same as the one before, but accepting a key-value pairs object for arguments injection.
nodelive.$require(...args)
Allows to require
files.
nodelive.$import(...args)
Allows to importFresh
(like a require
but without cache) files.
nodelive.$resolve(...args)
Allows to path.resolve
files.
Additionals
When interaction in live inside your programs, you have a global API automatically injected to global
object.
$hasnodelive
:boolean
indicating if the library was loaded.$nodelive
: masterobject
of the API.$dirname
: same asprocess.cwd()
.$require
: same as usingrequire
but fromprocess.cwd()
.$import
: same as using uncachedrequire
but fromprocess.cwd()
$resolve
: same as usingpath.resolve
but fromprocess.cwd()
License
This project is under WTFPL or What The Fuck Public License, which means 'do what you want'.