How to uninstall Postgres on Mac?

Yesterday I wanted to run Postgres image on my mac but the docker was complaining that port 5432 is in use. I was pretty sure that I did not install Postgres on my machine,  and due to the Microservice settings that I intended to run locally, I only wanted to run Postgres on port 5432, not any other port. I have searched my local machine for a copy of running Postgres and the result was negative. I reached to a good friend (Dave Oxley) with the awesome Linux background and he guided me to find the running instance of Postgres and get rid of it. Here are the steps that I took:

  1. Finding the processor that is running the Postgres instance:

sudo lsof -i tcp:5432

       Result:

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 6975 postgres 4u IPv6 0xb82fa8ce4a70a695 0t0 TCP *:postgresql (LISTEN)
postgres 6975 postgres 5u IPv4 0xb82fa8ce4fc9647d 0t0 TCP *:postgresql (LISTEN)

by looking at the result it is very clear that there is a parent processor that is running the Postgres, so technically killing PID was not helpful because it parent processor would run it again. The only option was uninstalling the Postgres, but how do I know where that Postgres was in my machine.

2. To find the answer I ran this command:

 ps -ef |grep 6975

and running this command gives me this result:

502 6975 1 0 11:40AM ?? 0:00.04 /Library/PostgreSQL/10/bin/postmaster -D/Library/PostgreSQL/10/data
502 6982 6975 0 11:40AM ?? 0:00.00 postgres: logger process
502 6984 6975 0 11:40AM ?? 0:00.00 postgres: checkpointer process
502 6985 6975 0 11:40AM ?? 0:00.04 postgres: writer process
502 6986 6975 0 11:40AM ?? 0:00.01 postgres: wal writer process
502 6987 6975 0 11:40AM ?? 0:00.00 postgres: autovacuum launcher process
502 6988 6975 0 11:40AM ?? 0:00.00 postgres: stats collector process
502 6989 6975 0 11:40AM ?? 0:00.00 postgres: bgworker: logical replication launcher
501 7073 6601 0 11:45AM ttys005 0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn 6975

form the first line of log you can see that Postgres version 10 was running in my machine, so I head to that directory and uninstalled the Postgres and then I was able to run docker without any problem.

 

🙂

How to send email in Node.Js?

Hey guys,

Today I want to show you how to use nodemailer in node.js to send email.

Node.js has a very active community that are adding new modules daily to the npm (node package module or node package manager), one my favorite module in node.js is nodemailer, this module helps you to send email to any recipient that you want, these are the steps that you need to take in order to use this module.

  1. You must install nodemailer as it is not a core module in node.js
Npm install nodemailer
  1. Create a object from the module.
const nodemailer = require('nodemailer');

 

  1. Create function that sends email and code all the configurations in this function:
</pre>
<pre>function sendEmail() {
// you need to create an object that contains all the sender email configuration
  var transporter = nodemailer.createTransport({
    service: 'Gmail',
    auth: {
      user: 'your@email.com',
      pass: ' you password '
    }
  });
// You need to create an email content
  var mailOptions = {
    from: 'janfeshan.mehran@gmail.com',
    to: 'info@codingtips.net',
    subject: 'Your order is ready',
    text: 'Your order is ready for delivery',
    html: 'Your order is ready for delivery'
  };
//Pass the email content to transporter in order to send email.
  transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
      console.log(error);
      res.redirect('/');
    } else {
      console.log('Message Sent: ' + info.response);
      res.redirect('/');
    }
  });
}</pre>
<pre>