This community-built FAQ covers the “Accessing the Process Object” exercise from the lesson “Learn Node.js”.
Paths and Courses
This exercise can be found in the following Codecademy content:
Learn Node.js
FAQs on the exercise Accessing the Process Object
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Need broader help or resources? Head here.
Looking for motivation to keep learning? Join our wider discussions.
Learn more about how to use this guide.
Found a bug? Report it!
Have a question about your account or billing? Reach out to our customer support team!
None of the above? Find out where to ask other questions here!
in process.argv, what decides which number to input within square parantheses?
1 Like
I really don’t get what I am doing wrong here.
Task 1 is: " 1.
We want the program in app.js to store the starting amount of memory used ( heapUsed
), perform an operation, and then compare the final amount of memory used to the original amount. Right now, the initialMemory
variable is assigned to null
. Change this line, so that initialMemory
is instead assigned the value of the heapUsed
property on the object returned from invoking the process.memoryUsage()
method."
So the solution in the terminal should be
$ node
global.initialMemory = process.memoryUsage().heapUsed
Right?
the process.argv[2] It starts on 2 because process.argv[i]
contains the whole command-line invocation: so 2 is index 0, 3 is index 1 and so on
For Example:
Invoking this at the node command
let word = process.argv[2]; )
node app.js Codecademy is Great
word returns: Codecademy
let word = process.argv[4]
node app.js Codecademy is Great
word returns: Great
Hope this helps…
For question 2 of this task - this is the process we followed;
Type node app.js Codeacademy
This should print the following
Your word is null
Starting memory usage: 3144000.
Current memory usage: 4051824.
After using the loop to add elements to the array, the process is using 911432 more bytes of memory.
As we want the change the output of the variable let word from null to Codeacademy, we change the value like so;
let word = null;
to
let word = process.argv[2];
The number in the square bracket above refers to the application > file > word of the line we entered at the begining. node app.js Codeacademy
0 = node
1 = app.js
2 = Codeacademy
Therefore, when we click the ‘Check work’ button, our new word value should be Codeacademy
For anyone stuck on Task 1. The solution i found when trying to store heapUsed to initialMemory ended up being quite simple.
Type node into the terminal,
Wait for > which is the REPL waiting to eval the next line
Enter global.initialMemory = process.memoryUsage() into the terminal
The expected output should be;
{ rss: 27279360,
heapTotal: 5767168,
heapUsed: 4511568,
external: 9347 }
Then change
let initialMemory = null
to
initialMemory = process.memoryUsage().heapUsed;
heapUsed in the object printed to the terminal is heapUsed: 4974072,
therefore when adding global.initialMemory = process.memoryUsage().heapUsed to the terminal the value should be output to a number that reflect heapUsed (this may bea different vaule)
hello guys. I am new in learning node.js anybody can help me to understand what this exercise wants. actually I didn’t understand what the node is and why are we writing node code in terminal?
2 Likes