Node JS - Node js REPL More Commands - Node - Node JS tutorial - webnode

  • This is a node.js tutorial for beginners to teach commands and operators in REPL.
  • Find Length of an array using underscore ( _ )
 nodejs rpel command

Learn Nodejs - Nodejs tutorial - nodejs rpel command - Nodejs examples - Nodejs programs

  1. Initialize an array as [1,2,3]. On pressing enter key, the initialized array is displayed as [ 1, 2, 3 ] .
  2. Fetch the length of the array using the node.js command _.length.If we provide (_+1) the output will be displayed as 4.

REPL context and global scope variables

  • Below follow commands to
  • 1.expose the global variable explicitly through REPL.
  • 2.access these global variables.

Sample code with context variable :

  • Create a javascript file with name as repl_val.js and enter the below code:
const repl = require('repl');
var msg = 'message';
repl.start('> ').context.m = msg;
 nodejs command code

Learn Nodejs - Nodejs tutorial - nodejs command code - Nodejs examples - Nodejs programs

  1. Declaring the variable repl_cmd and specifying it as required field.
  2. Initializing the variable myMsg with the value “WikiTechy”.
  3. Mark the “val” variable as context variable and assign the myMsg value to the val variable.
  • I placed my file in the path D:\wikiTechy\7.node.js\3.repl-Commands\repl_val.js.
  • Go to command prompt and type the below command:
node D:\wikiTechy\7.node.js\3.replCommands\repl_val.js -> Press enter key
val -> press enter key
  • This will display the context of “val” which is placed in the javascript file as shown below:
 nodejs command output

Learn Nodejs - Nodejs tutorial - nodejs command output - Nodejs examples - Nodejs programs

More REPL commands to learn nodejs :

Command Purpose
.break While inputting a multi-line expression, sometimes you get lost
or just don't care about completing it. .break will start over.
.clear This command will reset the context object to an empty
object and clears any multi-line expression.
.exit It will close the I/O stream,
which will cause the REPL environment to exit.
.help It shows the list of special commands.
.save This command saves the current REPL session to a file.
.load It loads a file into the current REPL session.

Related Searches to node.js REPL More Commands

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.