Note that once youve invoked this module, your node program will not terminate. So, this is it for this tutorial, Hope you guys enjoy the tutorial, feel free to drop any comments in the comment section below. Readline allows reading of a stream (such as STDIN) on a line-by-line basis. RL.question('What is your name? ', (name)=> years old, you can enjoy our services`) So this is called the arrow function in the assets. Now this callback function is going to bring back an answer or should I say a “name” because that’s what we are asking here right. And then this question will be something like “What is your name?” and this is going to take a callback function and we can use some of the ES6 features thereby doing the parentheses by itself instead of putting the function name in front of it. Heres the easiest way to read lines from a file, without any external. Let’s go ahead.īasically, ask a question because we are terminal or program right. Since Node.js v0.12 and as of Node.js v4.0.0, there is a stable readline core module. Now that we have this variable(RL) we can play around with it. var RL = readline.createInterface(process.stdin, process.stdout) The first one is the Standard Input Object and the second one is the Standard Output Object. Now, I’m going to set up another variable “ RL” here and then I use this variable on top and I’m going to use a function here call the function to create an interface() and this is going to take two parameters, two arguments here. Readline module makes it easier for input and reading the output given by the user. This module wraps up the process standard output and process standard input objects. So basically const is a constant and this is like a variable but something that you’re not going to be able to change the value of it later. Readline Module in Node.js allows the reading of input stream line by line. Let’s set this up first and we can use constants if you want to do that here and this (const)constant is a new thing in ES6. So instead of using the process standard input and output directly, we can just use the Node js Readline Module to do a little bit more complex things more easily. Node js Readline Module is basically a wrapper around the process standard output and process standard input objects and you know when I said a wrapper I mean more functionality on top of it and something easier to understand and it’s just a lot easier to do. Now create a variable readline and assign require() function so that the Node js Readline module is included in to file. So let’s go ahead and create a new file named readline.js. Let’s talk about how another module that I like to use a lot and is the Node js Readline Module. Hi, in this tutorial we want to take a look at a couple more modules here so that you guys can have a better understanding of some of the modules and their importance.
0 Comments
Leave a Reply. |