What's the JavaScript syntax after the require() call?

what'd
how to pronounce what
what w
whatsapp
whatsapp app
what's
what does
what c

The following code is from the Node.js course I am following:

var args = require("minimist")(process.argv.slice(2), { string: "name"});

I understand that a module is being imported, but I don't understand the second set of parentheses after the require() call:

require("minimist")(this part I don't understand)

Specifically, what is the second set of parentheses in terms of syntax?

I know how slice() works, and I understand that string: "name" creates a command line argument to check for, but what method is being called through the require() call, and how?

PS: The course (by Kyle Simpson) indicates that the above syntax will be explained later, but I haven't been able to locate the specific part, and I don't like to proceed without understanding something. I am new to both JS and Node.js.

In this case it looks like the module you are requiring is simply returning a function which you are immediately calling with () and passing in two arguments: process.argv.slice(2) and { string: "name"}

So if your module looked like this:

// minimist.js
function test(str){
    console.log(str)
    return "Called with:" + str
}
module.exports = test;  // exports the function

you could use it like:

var arg = require('./minimist.js')("Hello") // calls the function minimist.js exported

What, what as a pronoun, it can be the subject, object, or complement of a verb. It can also be the object of a preposition. used to ask for information about people or things: What time is it? What books did you buy ? What did you wear ?

Try to name each part to figure it out: Let's put it this way:

var args = tmp(v1, v2);

As you can see, that is clearly a function calling. Right?

And now, imagine that:

var tmp=require("minimist");
var v1=process.argv.slice(2);
var v2={ string: "name"};

Now you got it: tmp -namely the value returned by slice()- must be necessarily a function that accepts two arguments.

What Part of Speech is “WHAT”, is commonly classified as an adjective if it is used to introduce a noun or a noun phrase. What definition, (used interrogatively as a request for specific information): What is the matter? See more.

minimist is a package to parse command line arguments, and it exports a function.

require('minimist') will return a function like function(args, opts={}). Then you pass arguments to this function.

First argument - process.argv.slice(2)

process.argv is an array of parts of your command. For example if you type in your terminal

node app.js --test -x 1 --name '123'

Your process.argv will be an array

['node', 'app.js', '--test', '-x', 1, '--name', '123']

Here ['node', 'app.js'] is obvious you have to call. So to get your options you have to use .slice(2), and it will be

['--test', '-x', 1, '--name', '123']

Now go to the next...

Second argument - { string: "name" }

From minimist documentation you can find the following

opts.string - a string or array of strings argument names to always treat as strings

It means your 'name' argument will be accepted as string. From example above:

name = '123' // not 123

Hope it's clear now for you. Comment if anything is not.

Word, I will do what I can to help you. TranslationsEdit. show ▽what? (interrogative pronoun)  Definition of what (Entry 3 of 3) 1 a — used as an interrogative expressing inquiry about the identity, nature, or value of a person, object, or matter What minerals do we export?

what definition: 1. used to ask for information about people or things: 2. used in questions that show you are…. Learn more. WhatsApp Messenger: More than 2 billion people in over 180 countries use WhatsApp to stay in touch with friends and family, anytime and anywhere. WhatsApp is free and offers simple, secure, reliable messaging and calling, available on phones all over the world.

Usage Note: When what is the subject of a clause, it takes a singular verb if the word or phrase that completes the sentence (the complement) is singular, as in I​  WhatsApp Messenger: More than 2 billion people in over 180 countries use WhatsApp to stay in touch with friends and family, anytime and anywhere. WhatsApp is free and offers simple, secure, reliable messaging and calling, available on phones all over the world.

What we mean by a 'second peak' of coronavirus. By Scottie Andrew, CNN. Updated 6:12 AM ET, Thu May 28, 2020. Where early US coronavirus hotspots stand  Release year: 2019. Desperate to secure funding for her med tech startup, an idealistic scientist and her husband strike an outrageous deal with a mysterious investor. Putting their trust on the line, a couple considers a proposal from a notorious investor: a night with Sean in exchange for funding Lisa’s startup.

Comments
  • stackoverflow.com/questions/22213980/…
  • @ptts That link covers argv. I know how argv is passed to the process. My question concerns the syntax as I have explained in detail in my question (at least I thought I made myself clear).
  • OK, I understand your example. Will accept as soon as SO lets me. Thank you. Didn't know about module.exports, so thanks for that as well.
  • Thank you so much Rashad, Təşəkkür edirəm. Really clear now.