HWZ Forums

Login Register FAQ Mark Forums Read

node js documentation

Like Tree1Likes
  • 1 Post By davidktw
Reply
 
LinkBack Thread Tools
Old 26-07-2018, 09:07 PM   #1
Master Member
 
addictzz's Avatar
 
Join Date: May 2010
Posts: 2,495
node js documentation

I have question on how to read node js documentation. I often see these kinds of argument notation below:

- http.createServer([options][, requestListener])
*arguments in square bracket ie. [options]
*square bracket, comma, and argument name ie. [, requestListener]
- emitter.emit(eventName[, ...args])
* [,...args]?
- http.get(options[, callback])
* arguments with no bracket ie. options

what do these argument notation mean?
__________________
I am at West (Bkt Batok proximity) for Amazon Tompang.

Last edited by addictzz; 26-07-2018 at 09:09 PM..
addictzz is offline   Reply With Quote
Old 26-07-2018, 09:18 PM   #2
Master Member
 
addictzz's Avatar
 
Join Date: May 2010
Posts: 2,495
I can always guess by reading thru the explanation. But I would like to know officially what they meant.

PS: After more searches around the net, found out that this square bracket around arguments mean it is optional argument. And a comma inside square bracket means that it is optional argument with a default value.
__________________
I am at West (Bkt Batok proximity) for Amazon Tompang.
addictzz is offline   Reply With Quote
Old 26-07-2018, 11:48 PM   #3
Arch-Supremacy Member
 
Join Date: Apr 2012
Posts: 11,107
http.createServer is meant to create the server in either production mode based on your hosting platform or development mode whichever your localhost port is.

http.get, http.put, http.post, http.delete and etc are just basic CRUD. you need the callback to do basic request, response or to the next "function" or "object".

I am not focused on backend logic, so correct me if i am wrong.
jgyy1990 is offline   Reply With Quote
Old 27-07-2018, 03:13 AM   #4
Arch-Supremacy Member
 
davidktw's Avatar
 
Join Date: Apr 2010
Posts: 10,105
I have question on how to read node js documentation. I often see these kinds of argument notation below:

- http.createServer([options][, requestListener])
*arguments in square bracket ie. [options]
*square bracket, comma, and argument name ie. [, requestListener]
- emitter.emit(eventName[, ...args])
* [,...args]?
- http.get(options[, callback])
* arguments with no bracket ie. options

what do these argument notation mean?
I might not entirely correct, but across numerous documentations that I have come across. The above is a more a loosely created notation to explain the arguments formats.

[ ... ] is normally associated with OPTIONAL

The comma placed inside the square brackets is similar to the regex notation as such

A(,B)?
meaning the regex is match

A A,B
meaning if you are going to put in a 2nd argument, it should be separated from the first using a comma.

Hence

http.createServer([options][, requestListener])
Would means you can invoke the createServer method using the following possible arguments

http.createServer(); http.createServer({ .... }); http.createServer({ .... }, function() { ... });
That being said, the documentation is loosely presented for example.

The above method syntax does not in anyway denote that the first OBJECT "options" can be optionally left out and immediately just specify the 2nd argument, in which the syntax should allow the comma(,) be placed immediately in front of the function argument as such

http.createServer(, function() { ... });
Obviously, if you try doing this, the javascript parser will choke. So this is more of common sense instead of a formal syntax declaration.

Hence you can write either of these for the above case

http.createServer(function() { ... }) http.createServer(() => { ... })
This is why I say this is a very loosely written documentation

A more formal way of writing the above intention should be the following

http.createServer([options | requestListener]) http.createServer(options, requestListener)
emitter.emit(eventName[, ...args])
The above, it should be interpreted as eventName is mandatory, and there could be zero or more arguments the follow, as such.

emitter.emit(eventName) emitter.emit(eventName, arg1) emitter.emit(eventName, arg1, arg2, ..., argN)
The last I will leave to you interpret it for yourself
Ryuichi likes this.
davidktw is offline   Reply With Quote
Reply
Important Forum Advisory Note
This forum is moderated by volunteer moderators who will react only to members' feedback on posts. Moderators are not employees or representatives of HWZ. Forum members and moderators are responsible for their own posts.

Please refer to our Terms of Service for more information.


Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On