Quick Contact


    REPL in Node JS

    REPL stands for Read Evaluate Print Loop. It is format of interacting with these interpreters which basically provide you prompt and then you can type something in prompt, hit enter ant it executes what you typed in prompt, gives you the result and show you the prompt again. So in this the process is that you read what you have typed, evaluated, print the result and then show you the prompt. So, it’s basically the loop so that’s what REPL actually means. So, node by default has ripple built into it so you can try out node syntax, execute node code without even writing those statements in a file. You can directly write it in the node ripple command. So, the way to start the node replica is really simple by just typing Node.

    To the node prompt let’s write JavaScript code and it executes it. So, write something like some operation such as 1+1 etc as below-:

    You can also run any random commands in JavaScript. Like “Var a” so output comes through REPL process. More you can understand with code. As -:

    	>1+1
                   2
    	>var a;
    	               Undefined
    	>a = 10;
    	               10
    	>a
    	              10
    	>a*2
    	             20
    	>var b = a+3;
    	            Undefined
    	>b
    	            30
    
    	

    So these all operation includes evaluation of expressions and then returning the answer. So, basically JavaScript code is executing in this kind of repeated loop format where you can prompt and then you can type it and wait for it to execute. So, above commands are simple you can start with. You can also try multiline commands like

    	If (a>9) {
    	... console.log (“a is greater than 9”);
    	...}
    	a is greater than 9
    	Undefined
    	>a
    	10
    	

    “…” using these continuous dots basically saying it’s indented at a little bit and say i know it’s not the end that more statements are coming so its waiting and when closing curly braces entered so that say lines ended and ready to execute.

    So in this all Node Ripple play around with it and have some fun but before it let’s look the way to do it.

    Note-:

    CNTRL+ C is used to exit the operation or CNTRL+D or type .exit

    Important thing is to remember that every time you quit the ripple all the functions and variables that you have created and effectively erased because all that stay in the memory. So, you create all the available functions and then when you exhibit able and then start a new repetition by a node, note the variable that you have created before is obviously is not going to exist like you would expect it to like any other program all these things are in memory. So, you start out with a clean session every time you start an order

    Copyright 1999- Ducat Creative, All rights reserved.