Using Mongoose / MongoDB $addToSet functionality on array of objects

You need to use the $ne operator. var data = { ‘kind’: ‘tortoise’, ‘hashtag’: ‘foo’ }; Model.update( { ‘articles.hashtag’: { ‘$ne’: ‘foo’ } }, { ‘$addToSet’: { ‘articles’: data } } ) This will update the document only if there is no sub document in the “article” array with the value of hashtag equals to … Read more

Missing “key” prop for element. (ReactJS and TypeScript)

You are rendering an array of elements, so React needs a key prop (see react docs) to identify elements and optimize things. Add key={topic.id} to your jsx: return ( <div> <h2>Results List</h2> {topics.map((topic: any) => <div className=”panel panel-default” key={topic.id}> <div className=”panel-heading”>{topic.name}</div> <div className=”panel-body”>{topic.description}</div> </div> )} </div> );

Node Express Content-Length

The response has Transfer-Encoding: chunked. Here Content-Length is not applicable, because the content is sent in one or more parts (chunks) inside the response body, with a marker indicating the byte-length of each individual chunk. http://en.wikipedia.org/wiki/Chunked_transfer_encoding Node.js defaults to Transfer-Encoding: chunked. However, this is disabled by setting the Content-Length header on the native http response … Read more

npm throws ENOENT warnings on every install/uninstall/ls

Error message might be caused by missing package.json file. Change directory to your project’s local directory, as an example (instead, use current working directory of your project): cd /var/www/nodeBot Following string will write package.json: npm init Answer menu-driven questions or use –yes to blast past them. Then press enter at the end to write out … Read more

node.js http.get hangs after 5 requests to remote site

Here’s the reason of the “exactly 5”: https://nodejs.org/docs/v0.10.36/api/http.html#http_agent_maxsockets Internally, the http module uses an agent class to manage HTTP requests. That agent will, by default, allow for a maximum of 5 open connections to the same HTTP server. In your code, you don’t consume the actual response sent by Google. So the agent assumes that … Read more

How do I replace deprecated crypto.createCipher in Node.js?

So lets say it like: Replace deprecated crypto.createDecipher usage with crypto.createDecipheriv why? because: according to the deprecation docs it was due to security concerns. Using crypto.createCipher() and crypto.createDecipher() should be avoided as they use a weak key derivation function (MD5 with no salt) and static initialization vectors. It is recommended to derive a key using … Read more

Mongoose multiple connections

Mongoose handling connections via connections pool http://mongoosejs.com/docs/connections.html You can use server: {poolSize: 5} option for increase/decrease pool (number of parallel connections) If you need connections to different databases look here Mongoose and multiple database in single node.js project Example of multiple connections: var mongoose = require(‘mongoose’) var conn = mongoose.createConnection(‘mongodb://localhost/db1’); var conn2 = mongoose.createConnection(‘mongodb://localhost/db2’); var … Read more

How tunneling services like ‘Localtunnel’ works without SSH?

The Short Answer (TL;DR) The Remote (i.e. the localtunnel software on your computer) initializes the connection to the Relay (i.e. localtunnel.me) acts as a multiplexing proxy and when Clients (i.e. web browsers) connect, the relay multiplexes the connections between remotes and clients by appending special headers with network information. Browser <–\ /–> Device Browser <—- … Read more