Reputation: 4615
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?
if one, why writeHead(200,
followed a comma?
if two, why statusCode[, statusMessage][, headers]
without a
comma?
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
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