Stream highWaterMark misunderstanding

is the data you try to write really “rejected” when the #write method returns false ? Or is it buffered (or something else) ? The data is buffered. However, excessive calls to write() without allowing the buffer to drain will cause high memory usage, poor garbage collector performance, and could even cause Node.js to crash … Read more

saslprep warning when using MongoClient.connect()

Just install the saslprep package and the warning will go away. The mongodb package looks for the saslprep package, but works without it; it’s an optional dependency. If you look in the mongodb source: let saslprep; try { saslprep = require(‘saslprep’); } catch (e) { And, later: if (!saslprep) { console.warn(‘Warning: no saslprep library specified. … Read more

Using node.js to listen on 2 different ports

Just create another instance of http and put it to listen to the port you are interested. Let me show you an example: var http = require(‘http’); http.createServer(onRequest_a).listen(9011); http.createServer(onRequest_b).listen(9012); function onRequest_a (req, res) { res.write(‘Response from 9011\n’); res.end(); } function onRequest_b (req, res) { res.write(‘Response from 9012\n’); res.end(); } Then, you can test it (with … Read more

Nodejs – Joi Check if string is in a given list

You are looking for the valid and invalid functions. v16: https://hapi.dev/module/joi/api/?v=16.1.8#anyvalidvalues—aliases-equal v17: https://hapi.dev/module/joi/api/?v=17.1.1#anyvalidvalues—aliases-equal As of Joi v16 valid and invalid no longer accepts arrays, they take a variable number of arguments. Your code becomes var schema = Joi.object().keys({ firstname: Joi.string().valid(…[‘a’,’b’]), lastname: Joi.string().invalid(…[‘c’,’d’]), }); Can also just pass in as .valid(‘a’, ‘b’) if not getting the … Read more

Error: Nock: No match for request

Use .log(console.log) to see the exact error message. EX : nock(‘https://test.org/sample’) .persist() .log(console.log) .get(‘/test’) .query({}) .reply(200, response); When you use this and run the test, you will see something like this in the console matching https://test.org/sample/test to GET https://test.org/sample/test with query({}): **true/false**. If it says true, your request should be good. But if it says … Read more