In this video, we are going to learn how to pass arguments to our Node.js functions.
So let's get started.
So in order to do that, I'm going to create a EVE lecture folder and create logger that JS file.
So in this file I'm going to look again, but this time I'm going to lock process that.
Argh!
So this is the predefined property and command that we can get the arguments from the environment.
So let's see how it will be work.
In our Node.js function.
We basically lock the incoming arguments from the process.
In order to do that, please save this file and come to lecture regarding the lecture folder structure
and you can run the node command note, empty character and logs.
If you hit enter, you can see that we have two predefined arguments into our process.
We object, so that means we can get the arguments from the process object.
And in the beginning we have already two arguments defined in our application.
The first one is the Node.js exit and the second one is the file that is running now, which is the
logs.
Okay.
So if we would like to pass more arguments, we can write to command, for example, not logs.
Now put the empty character and give the argument and also put empty character, give another argument.
So I have created two new argument into our node command.
If you hit enter, you can see that this time we have four arguments is located under the process arg
we object so see that we can get arguments and run log logs with the node command.
So if you update the code to get our.
Excuse.
Arguments.
For example, I'm going to set the argument this is the array that we can reach the values.
So that's why I'm going to.
Get the argument too.
And argument three, which is the name and the surname operation.
So if you save this file and run this command again.
It entered.
We can see that we basically get the argument to and argument three.
So if we go further to create a function.
I'm going to create any longer function.
Let me put this in here.
Yes.
As you can see that we have created a local function that is including the name and the surname information.
And we basically lock these name and surname information with a given text message.
So also we have to invoke this function into our JS file.
So here you can find the latest code.
So if you run the same command with these two argument, name and surname, hit enter.
As you can see that we can manage to run local JS with getting the process arguments from the Node.js
function.