how to make express port to listen to nodemailer port - node.js

I have been having issues trying to use my zoho mail account with nodemailer in my cloud 9 workspace. When i send the request all it returns back after some time is connection timeout. i contacted my dns name provider they told me to ensure that port 465 is open in my server.. but am really stuck don't know how to change it or to check it any help
how i listen to port in my express app
app.listen(process.env.PORT, function(){
console.log(process.env.PORT)
})
how do i configure it to listen to other ports like 465 and get my nodemailer working..

Since you're listening on the port specified in your process environment variables, run your app passing it in via PORT:
On Unix:
PORT=465 node <appFile>.js
If you're on windows you can use cross-env to pass in the Environment variables, you'll just need to install it globally with npm i -g cross-env.
cross-env PORT=465 node <appFile>js

Related

listen EADDRINUSE: address already in use -> No matter what port I use?

NodeJS version: LTS 12.17 installed like this:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
I have a pretty weird issue:
One of my NodeJS app suddenly reports: listen EADDRINUSE: address already in use and it doesn't help anything no matter what port # I try to change it to?
The full trace-stack looks like this:
Error: listen EADDRINUSE: address already in use 0.0.0.0:6080
at Server.setupListenHandle [as _listen2] (net.js:1313:16)
at listenInCluster (net.js:1361:12)
at doListen (net.js:1498:7)
at processTicksAndRejections (internal/process/task_queues.js:85:21)
I'm listening like this (_wl = a Winston logger instance):
> _server.listen(_port, '0.0.0.0', function () { _wl.info('SERVER STARTED! (listening on port # ' + _port + ')')});
I have just setup this AWS EC2 Ubuntu 20.04 instance - so I guess somehow it has something to do with this. It has been working for years on a lot of different instance earlier Windows (I guess I have never run it on Ubuntu earlier).
I execute like like:
1. cd into folder
2. node ./server.js (I have also tried to use Sudo)
Can it have something to do with permissions?
I have tried to allow all in /out going traffic in the server atteched Security Group.
I have check that the firewall in Ubuntu 20.04 is disabled as well.
Also, on the same server I'm running a Python app which exposes a web socket server and the NodeJS app has no issue to subscribe to this connection...
And yes - I have tried to check all ports in use at the server and only few ports are in use.
The NodeJS app also try to expose a websocket server at a given port - but no matter what port I try to use I get the error above.
Sorry!
I use express in my NodeJS apps and most of my apps contain the following line:
app.listen(port); // In this case port # 6080
Later on in the current app (in which I experience the issue described above) I initialize a web socket server as well like this:
const _server = require('http').createServer();
_server.on('request', app);
_server.listen(_port, '0.0.0.0', function () { _wl.info('WEB SOCKET SERVER STARTED! (listening on port # ' + _port + ')')});
in the code above both port and _port used the same ENV variable/setting(6080). Do to my app/Express in this case actually didn't use the app.listen(port) to anything and that Windows just choose to overrule the port's use-case when the web socket server afterwards got initialized with the same port number --> is the reason why I never have experienced any issues on Windows. But Linux/Ubuntu is more sensitive in this regard.
Cheers! :-)

Access NodeJS server installed on Linux server

I created my App from this boilerplate
https://github.com/Bikranshu/express-react-boilerplate
Now I uploaded it to a live Linux server and Node server is running.
Screenshot of running server
But I am unable to access it through Browser with IP address of server.
http://ip_address:3000
After waiting long in browser it is showing timeout error.
Please guide me how can I access the node/react app from browser.
Server running at <ipaddress> is a local IP, are you in a different network than the server? If so, you should be typing https://<public ipaddress>:3000
UPDATE
Hosting services usually only forward port 80 (http) or 443 (https.) This means that your port 3000 is not allowed for public access. To fix your problem you need to change the listening port.
Check line 42 on
server/app.js change 'port' to "80" or check package.json and edit npm start to set port to 80

Running node app digitalocean and accessing it

Im running my node app with grunt on a DO droplet. I start the server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:3000
But when I navigate to my dropletIP:3000 I cannot see the app, I get:
This site can’t be reached
mydropletIP refused to connect.
Shouldn't my app be available? I don't have nginx or anything installed.
I was having similar problem but the solution was simple. Change from 'localhost' to '0.0.0.0' i.e
.listen(8080, '0.0.0.0');
And then to test your api just enter your static ip of droplet with port that you have entered i.e droplet-ip:8080
Check the particular port is opened or not ,using following command
sudo ufw status
If any Firewall enabled and any port is block means you can see that.
netstat -an | grep "LISTEN " ( List of listening port on server)
I need this info ,then only we can find a problem

Heroku running a node module server

I am trying to create a node app that runs a module called noodlejs. This starts its own server running on port 8888 (on my local version). I have pushed the changes to heroku and no errors are caused. However how do I now access the noodlejs server on port 8888? Is this possible or does it need to run on another port?
Thanks!
I don't think you can run the app on port 8888 or any other port for that matter on Heroku. You can only choose between 80 or 443. And to do that, you use process.env.PORT environment variable that Heroku exposes.

Node.js Deployment in openshift

I was trying to deploy a Node.js application to the openshift as in this link here
I understand this code
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('Hello Http');
});
server.listen(3000);
and there is no issue running it locally
$ node server.js // saved as server.js
However, how does this work when I commit this application in openshift? This is very simple code. I have some downloaded code that is a chat application and client-server need to configure to listen on some port (I was using port number 3000 in my localhost).
It works on port number 3000 in localhost but how can I make it to work in Openshift?
You need to listen on port process.env.OPENSHIFT_NODEJS_PORT. So something like this should work:
server.listen(process.env.OPENSHIFT_NODEJS_PORT || 3000);
See here for example: Error: listen EACCES on Openshift app
Hey the issue with socket.io is that you have that npm package installed local but not in openshift (dependencies don't get pushed). For that you can login thru ssh (look for "Want to log in to your application?" in right menu in openshift control panel, follow instructions and use the ssh connection provided) then login with terminal o Putty, and go to:
cd app-root/repo
or
cd $OPENSHIFT_REPO_DIR
and then
npm install socket.io
I've used that to install mongoose and other dependencies without trouble. Also you can use
node server.js
from command line to run the site ;)

Resources