The problem in your code is, that params.username can be either a string
or a string[]
.
The following scenario returns a simple string
const {query} = url.parse('example.com?test=1', true);
// query.test === '1'
while the example below returns an array because the same query-parameter key is used twice
const {query} = url.parse('example.com?test=1&test=2', true);
//query.test === ['1', '2']
So you could handle the array case explicitly e.g.
const username = Array.isArray(params.username) ? params.username[0] : params.username