Albert.Qing
Albert.Qing

Reputation: 4615

what's the meaning of '[,params_name]' in node.js?

Here is node.js document about response.writeHead(statusCode[, statusMessage][, headers])

I don't understand "statusCode[, statusMessage][, headers]",

Is it stand for one params or more?

where means I can pass json?

Is there any document show about these param's rule?

Example:

const body = 'hello world';
response.writeHead(200, {
  'Content-Length': Buffer.byteLength(body),
  'Content-Type': 'text/plain' });

Upvotes: 1

Views: 74

Answers (1)

Eric
Eric

Reputation: 97575

The rule is simple - square brackets surrounding any text mean "this text is optional". So

response.writeHead(statusCode[, statusMessage][, headers])

Means all of the following

response.writeHead(statusCode, statusMessage, headers)
response.writeHead(statusCode, statusMessage)
response.writeHead(statusCode, headers)
response.writeHead(statusCode)

If the square brackets were nested as

response.writeHead(statusCode[, statusMessage[, headers]])

it means all of:

response.writeHead(statusCode, statusMessage, headers)
response.writeHead(statusCode, statusMessage)
response.writeHead(statusCode)

Noting that removing the outer set also results in the inner set being removed

Upvotes: 2

Related Questions