@@ -29,6 +29,21 @@ For example, you could add this to your bashrc file:
2929
3030 alias node="env NODE_NO_READLINE=1 rlwrap node"
3131
32+ ## Environment Variable Options
33+
34+ The built-in repl (invoked by running ` node ` or ` node -i ` ) may be controlled
35+ via the following environment variables:
36+
37+ - ` NODE_REPL_HISTORY ` - When a valid path is given, persistent REPL history
38+ will be saved to the specified file rather than ` .node_repl_history ` in the
39+ user's home directory. Setting this value to ` "" ` will disable persistent
40+ REPL history.
41+ - ` NODE_REPL_HISTORY_SIZE ` - defaults to ` 1000 ` . Controls how many lines of
42+ history will be persisted if history is available. Must be a positive number.
43+ - ` NODE_REPL_MODE ` - may be any of ` sloppy ` , ` strict ` , or ` magic ` . Defaults
44+ to ` magic ` , which will automatically run "strict mode only" statements in
45+ strict mode.
46+
3247## Persistent History
3348
3449By default, the REPL will persist history between ` node ` REPL sessions by saving
@@ -46,20 +61,86 @@ automatically be converted to using plain text. The new file will be saved to
4661either your home directory, or a directory defined by the ` NODE_REPL_HISTORY `
4762variable, as documented below.
4863
49- ## Environment Variable Options
64+ ## REPL Features
5065
51- The built-in repl (invoked by running ` node ` or ` node -i ` ) may be controlled
52- via the following environment variables:
66+ <!-- type=misc -->
5367
54- - ` NODE_REPL_HISTORY ` - When a valid path is given, persistent REPL history
55- will be saved to the specified file rather than ` .node_repl_history ` in the
56- user's home directory. Setting this value to ` "" ` will disable persistent
57- REPL history.
58- - ` NODE_REPL_HISTORY_SIZE ` - defaults to ` 1000 ` . Controls how many lines of
59- history will be persisted if history is available. Must be a positive number.
60- - ` NODE_REPL_MODE ` - may be any of ` sloppy ` , ` strict ` , or ` magic ` . Defaults
61- to ` magic ` , which will automatically run "strict mode only" statements in
62- strict mode.
68+ Inside the REPL, Control+D will exit. Multi-line expressions can be input.
69+ Tab completion is supported for both global and local variables.
70+
71+ Core modules will be loaded on-demand into the environment. For example,
72+ accessing ` fs ` will ` require() ` the ` fs ` module as ` global.fs ` .
73+
74+ The special variable ` _ ` (underscore) contains the result of the last expression.
75+
76+ > [ 'a', 'b', 'c' ]
77+ [ 'a', 'b', 'c' ]
78+ > _.length
79+ 3
80+ > _ += 1
81+ 4
82+
83+ The REPL provides access to any variables in the global scope. You can expose
84+ a variable to the REPL explicitly by assigning it to the ` context ` object
85+ associated with each ` REPLServer ` . For example:
86+
87+ // repl_test.js
88+ var repl = require('repl'),
89+ msg = 'message';
90+
91+ repl.start('> ').context.m = msg;
92+
93+ Things in the ` context ` object appear as local within the REPL:
94+
95+ mjr:~$ node repl_test.js
96+ > m
97+ 'message'
98+
99+ There are a few special REPL commands:
100+
101+ - ` .break ` - While inputting a multi-line expression, sometimes you get lost
102+ or just don't care about completing it. ` .break ` will start over.
103+ - ` .clear ` - Resets the ` context ` object to an empty object and clears any
104+ multi-line expression.
105+ - ` .exit ` - Close the I/O stream, which will cause the REPL to exit.
106+ - ` .help ` - Show this list of special commands.
107+ - ` .save ` - Save the current REPL session to a file
108+ > .save ./file/to/save.js
109+ - ` .load ` - Load a file into the current REPL session.
110+ > .load ./file/to/load.js
111+
112+ The following key combinations in the REPL have these special effects:
113+
114+ - ` <ctrl>C ` - Similar to the ` .break ` keyword. Terminates the current
115+ command. Press twice on a blank line to forcibly exit.
116+ - ` <ctrl>D ` - Similar to the ` .exit ` keyword.
117+ - ` <tab> ` - Show both global and local(scope) variables
118+
119+
120+ ### Customizing Object displays in the REPL
121+
122+ The REPL module internally uses
123+ [ util.inspect()] [ ] , when printing values. However, ` util.inspect ` delegates the
124+ call to the object's ` inspect() ` function, if it has one. You can read more
125+ about this delegation [ here] [ ] .
126+
127+ For example, if you have defined an ` inspect() ` function on an object, like this:
128+
129+ > var obj = { foo: 'this will not show up in the inspect() output' };
130+ undefined
131+ > obj.inspect = function() {
132+ ... return { bar: 'baz' };
133+ ... };
134+ [Function]
135+
136+ and try to print ` obj ` in REPL, it will invoke the custom ` inspect() ` function:
137+
138+ > obj
139+ { bar: 'baz' }
140+
141+ [ Readline Interface ] : readline.html#readline_class_interface
142+ [ util.inspect() ] : util.html#util_util_inspect_object_options
143+ [ here ] : util.html#util_custom_inspect_function_on_objects
63144
64145## repl.start(options)
65146
@@ -198,85 +279,3 @@ Example of listening for `reset`:
198279 console.log('repl has a new context');
199280 someExtension.extend(context);
200281 });
201-
202-
203- ## REPL Features
204-
205- <!-- type=misc -->
206-
207- Inside the REPL, Control+D will exit. Multi-line expressions can be input.
208- Tab completion is supported for both global and local variables.
209-
210- Core modules will be loaded on-demand into the environment. For example,
211- accessing ` fs ` will ` require() ` the ` fs ` module as ` global.fs ` .
212-
213- The special variable ` _ ` (underscore) contains the result of the last expression.
214-
215- > [ 'a', 'b', 'c' ]
216- [ 'a', 'b', 'c' ]
217- > _.length
218- 3
219- > _ += 1
220- 4
221-
222- The REPL provides access to any variables in the global scope. You can expose
223- a variable to the REPL explicitly by assigning it to the ` context ` object
224- associated with each ` REPLServer ` . For example:
225-
226- // repl_test.js
227- var repl = require('repl'),
228- msg = 'message';
229-
230- repl.start('> ').context.m = msg;
231-
232- Things in the ` context ` object appear as local within the REPL:
233-
234- mjr:~$ node repl_test.js
235- > m
236- 'message'
237-
238- There are a few special REPL commands:
239-
240- - ` .break ` - While inputting a multi-line expression, sometimes you get lost
241- or just don't care about completing it. ` .break ` will start over.
242- - ` .clear ` - Resets the ` context ` object to an empty object and clears any
243- multi-line expression.
244- - ` .exit ` - Close the I/O stream, which will cause the REPL to exit.
245- - ` .help ` - Show this list of special commands.
246- - ` .save ` - Save the current REPL session to a file
247- > .save ./file/to/save.js
248- - ` .load ` - Load a file into the current REPL session.
249- > .load ./file/to/load.js
250-
251- The following key combinations in the REPL have these special effects:
252-
253- - ` <ctrl>C ` - Similar to the ` .break ` keyword. Terminates the current
254- command. Press twice on a blank line to forcibly exit.
255- - ` <ctrl>D ` - Similar to the ` .exit ` keyword.
256- - ` <tab> ` - Show both global and local(scope) variables
257-
258-
259- ### Customizing Object displays in the REPL
260-
261- The REPL module internally uses
262- [ util.inspect()] [ ] , when printing values. However, ` util.inspect ` delegates the
263- call to the object's ` inspect() ` function, if it has one. You can read more
264- about this delegation [ here] [ ] .
265-
266- For example, if you have defined an ` inspect() ` function on an object, like this:
267-
268- > var obj = { foo: 'this will not show up in the inspect() output' };
269- undefined
270- > obj.inspect = function() {
271- ... return { bar: 'baz' };
272- ... };
273- [Function]
274-
275- and try to print ` obj ` in REPL, it will invoke the custom ` inspect() ` function:
276-
277- > obj
278- { bar: 'baz' }
279-
280- [ Readline Interface ] : readline.html#readline_class_interface
281- [ util.inspect() ] : util.html#util_util_inspect_object_options
282- [ here ] : util.html#util_custom_inspect_function_on_objects
0 commit comments