Category: node js

nodejs – apache2 – digital ocean – setup server with port forwarding

Let’s assume that you have 2 nodejs applications which will run on 2 different ports 9900 and 8800. You would like to have your server forward request to those ports properly. Following steps will be useful: 1.Install apache on digital ocean server 2.Set ports.conf as follow vi /etc/apache2/ports.conf Listen 80 Listen 443 3. Create 2 …


JS: map – filter – reduce methods

This blog is going to show you some example about how to use map, filter and reduce methods. This can help you quickly remember how to use it so that you can apply to your project development (at least as I am doing now ūüôā ) A- MAP 1. Convert an array into another array …


Mongodb client – nodejs : Find methods

Here are some useful query to help you interact with mongo db in node js server 1.To find all documents var requestsColl = myDb.collection(‘requests’); requestsColl.find({}).toArray(function(err, requests) { ¬† ¬†if (err) ¬† ¬† ¬† ¬†return callback(err); ¬† ¬†return callback(null, requests); }); This will return all document 2. To find all documents with filter var requestsColl = …


Mongodb Nodejs – Replace a value in array item from a nested object

If you have a document like this: { ¬† ¬† _id: <value> ¬† ¬†comments: [ ¬† ¬† ¬† ¬† { ¬† ¬† ¬† ¬† ¬† ¬† ¬†commentId: 1 ¬† ¬† ¬† ¬† ¬† ¬† ¬†comment: <value> ¬† ¬† ¬† ¬† }, ¬† ¬† ¬† ¬†{ ¬† ¬† ¬† ¬† ¬† ¬† ¬†commentId: 2 ¬† ¬† …


Change default title of swagger ui from node js application

Normally, if you are using swagger-tools to autogenerate API specifications, you will have by default the title of you site with “Swagger UI”. Following steps will have you to replace it with your title. Mac OS or Linux environment: 1- vi¬†node_modules/swagger-tools/middleware/swagger-ui/index.html <head> <meta charset=”UTF-8″> <title>YOUR WEBSITE TITLE</title> <link href=”https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700″ rel=”stylesheet”> <link rel=”stylesheet” type=”text/css” href=”./swagger-ui.css” > …