How do I setup my backend with DigitalOcean App Platform?

I have a relatively simple app, this is my first attempt at deploying a website, and it’s for my portfolio, so I apologize if this is elementary.

I had an express route setup to send an email from a form on the frontend, but I haven’t been able to get it to function since I’ve got it deployed on digitalOcean. relevant code below, let me know if I didn’t include information I should have! Thanks in advance!

Here’s the website…

This is the Index.js where the post route is.

var express = require(“express”);

var app = express();


const bodyParser = require(“body-parser”); const nodemailer = require(“nodemailer”); const cors = require(“cors”);

app.use(cors()); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json());“/send_mail”, cors(), async (req, res) => { let { content, contact, name } = req.body; console.log(“response -------->”, req.body, content, contact, name);

var transporter = nodemailer.createTransport({ service: “gmail”, auth: { user: process.env.MAILFROM, pass: process.env.MAILPASS, }, }); var mailOptions = { from: contact, to: “”, subject: " inquiry from " + name, text: contact + " <–contact----- " + "-----content-----> " + content, }; transporter.sendMail(mailOptions, function (error, info) { console.log(“this is in sendmail before if”); if (error) { console.log(error); } else { console.log("Email sent: " + info.response); } }); });

var server = app.listen(4000, function () { var host = server.address().address; var port = server.address().port; console.log(“i heard it all at http://%s:%s”, host, port); });

and here is where I am sending the info to the backend

const handleSubmit = async (evt) => { if (!disableButton(formState)) { setSent(true); try { const { contact, content, name } = formState; await“http://localhost:4000/send_mail”, { contact, content, name, }); } catch (error) { console.log(error); } } else { alert(“Please complete the form before submitting!”); } };

and the error Im getting

AxiosError {message: ‘Network Error’, name: ‘AxiosError’, code: ‘ERR_NETWORK’, config: {…}, request: XMLHttpRequest, …} code: “ERR_NETWORK” config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 0, adapter: ƒ, …} message: “Network Error” name: “AxiosError” request: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …} response: XMLHttpRequest {data: undefined, onreadystatechange: null, readyState: 4, timeout: 0, withCredentials: false, …} [[Prototype]]: Error

POST http://localhost:4000/send_mail net::ERR_CONNECTION_REFUSED

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Site Moderator
Site Moderator badge
September 22, 2022

Hi @largelapisanchor,

In the backend what port are you using for sending out the mails? I see you are trying to reach POST http://localhost:4000/send_mail net however I would assume you have some other backend configuration where you use 25/465 or 587, is that correct?

It’s possible port 25 is closed for external uses for new accounts. There are a few ways to go about the problem

  • try using ports like 465 or 587 for SMTP
  • use a third party solution only for your E-mails. Good examples are sendgrid.

To expand more on blocking port 25 for new accounts, this is something DigitalOcean has been doing to reduce spam on it’s network. It is more that we simply cannot accurately determine who is going to send it.

Stopping spam is a constant fight, so DigitalOcean has implemented some restrictions on newer accounts. Having said that, you can always contact them and ask for the port block to be lifted on:

More information here:

Hope that helps!

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up