#10: OS Module in Node.js: Methods, Properties, and Practical Examples

Thapa Technical
63 followers
Nov 27, 2024
Hello what's up guys today in this video
we will see os module in our nut j yes
guy today's video is going to be very awesome
because in yesterday's video we
saw path module and today we are going to see
os model basically Operating System
So let's check it out, you can see guys, there are
many methods here,
I have already written them all here
with definition and with usages,
so its I will share the link with you in the description below,
you must check it out,
but now we will go directly to
our code editor, but before that,
I am sharing with you all these PPT notes,
if you ever have any doubt, then
guys video. You will
find this second line in the description, okay,
you can see here in the pay and comment section
also, this is the access source
code, you must check it out, so guys,
I will go to my folder here.
I will create a new file, okay,
and its name will be guys
o module dot js, okay, and I
already have guys code, I am copy pasting
because it is not a big deal, it is a simple
code in which we will use its method. So
see right, now this is the thing, I
close it, open the terminal,
clear it, so it's a node and then
we have a mule, so now you will see
that guys, I am getting an error. It is
telling that reference error and OS is not
defined so that you know
anytime if you want to use any module
basically if you want to use the methods of that module
then we need to first
import basically we Need to first
require we have to gate it so
cost o will be equal to you can see
here we need to go with the Require and then we need to go
with OS module. Okay,
so simply in this way you have to get the module which is Guy OS.
Now
basically this is a constant variable of this OS,
inside it all the
properties and methods of our OS module come. Now it is your
choice, as it is written here first,
get the platform and user information,
then platform and user if you want to form the
platform and then your information.
Like if you want to
know the architecture of CPU then OD architecture is
in short let's say
how much free memory is there in your system then for that OD is
basically short form of
memory and the output it will give is in bytes then
total How many memories are there
in your system, so the
total memory, you are seeing, this
is the beauty of your modules, which are basically inbuilt
modules in your nut, where
each module has its own work. Given
that the
same way the O module deals with your operating system, guys,
if we go further down, let's
you know about the total up time of
your system, it gives you the
value in seconds and Then we need to go with
the up time methods then simple if we
go to home directory your home which
is the directory basically we
also saw in the path module what is the directory
basically your which is the main folder
You can get it here also, then host
name and host name, I cannot show you the
interface, network interface, all your IP
addresses and many other things. You will
get extra information in the network interface. If you want to
know about your CPU, then
guys o CP S my God means so
many things are available to you by default. So
you are seeing that when it comes to dealing with the server,
these nuts are like that. Awesome and
similarly, you will get what is your temporary directory
and what is your operating
system and if you use
maxx.use
then I clear it, now I will
hit enter, so see I have so many
data. Coming first, which
platform is your ws2 user information,
you will find its user ID, G ID,
user name, which is your home directory,
cell, it is visible to you in this manner
and if you go here then The
architecture of your CPU
is visible, that is x64 free memory, this much is your
total memory in bytes, again this is
visible in bytes, you are getting the up time
in seconds value,
so here also you get the home directory. It
was the same here also and the temporary
directory is the same. Basically, you remember that
if your system is lagging a little,
then we
delete whatever data is inside the temp directory, then
this is yours. And then which operating
system do you deal with and that is the guy with
windows.net works,
you will get so much data from it, you can't even imagine,
which CP of your CPU are
you using?
But I guess by showing this you have got the idea
that we just need to use the
module and the inbuilt methods in it.
We have to use them when we
work in a project, then you
can understand them in a better way. Be it
how we can use it,
how we can combine it with basically different modules,
but for now, it is
important to understand that yes, if anyone ever
asks about the architecture of CPU, How can
you find out in node then you
can say we should use the o module and there
is a method inside that and that is odd aa
architecture wala in this way then you will
get the value in this way and if you have
all this data If you want to know, then
go to Settings in the system and write system information
or press control r and
write system information, you will get everything there,
okay so guys, this is it, that's
all I know for this video today. The
module which is there will be a little easy but yes,
tomorrow's module which will be crypto, you are going to
enjoy it and after that in the file system,
finally we will create files,
read them, delete them, that means it will be fun,
it will be a code operation only then. Okay
but today's video was simple but it is good, it
feels good, it's all we know,
so guys, how did you like the video, let me know
in the comment section, I am providing the source code absolutely free,
please
like this video. Please share with your friends as much as possible
and our next target is 8
lakh subscribers so if you have not subscribed yet then
please do so and
a red bell icon is also visible on the right side,
hit that also so that you can watch the
awesome videos. Don't miss so guys
I will show you in tomorrow's video till then guys
thank you so much take
care
