Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/How to fix “failed to load resource: net::err_connection_refused”
Next
Answered
Kayla Martin
  • 5
Kayla Martin
Asked: May 17, 20222022-05-17T14:00:39+00:00 2022-05-17T14:00:39+00:00In: javascript

How to fix “failed to load resource: net::err_connection_refused”

  • 5

. Advertisement .

..3..

. Advertisement .

..4..

For the problem “failed to load resource: net::err_connection_refused”. I tried to fix it, but it doesn’t work and returns the result I want. Here is my program:

<form [formGroup]="angForm" novalidate>
  <div class="message">
  <h3> Write to us </h3>
  </div>
  <div class="form__top">
  <div class="form__left">
  <div class="form__group">
  <input class="form__input form__input--name" type="text" formControlName="name" placeholder="name" #name>
  </div>
  <div *ngIf="angForm.controls['name'].invalid && (angForm.controls['name'].dirty || angForm.controls['name'].touched)" class="alert alert-danger">
  <div *ngIf="angForm.controls['name'].errors.required">
  Name is required.
  </div>
  </div>
  <div class="form__group">
  <input class="form__input form__input--email" type="email" formControlName="email" placeholder="email" #email>
  </div>
  <div *ngIf="angForm.controls['email'].invalid && (angForm.controls['message'].dirty || angForm.controls['message'].touched)"
  class="alert alert-danger">
  <div *ngIf="angForm.controls['message'].errors.required">
  message is required.
  </div>
  </div>
  </div>
  <div class="form__right">
  <div class="form__group">
  <textarea class="form__input form__input--textarea" placeholder="Message" formControlName="message" #message
  rows="3"></textarea>
  </div>
  <div *ngIf="angForm.controls['message'].invalid && (angForm.controls['message'].dirty || angForm.controls['message'].touched)"
  class="alert alert-danger">
  <div *ngIf="angForm.controls['message'].errors.required">
  message is required.
  </div>
  </div>
  </div>
  </div>
  <flash-messages></flash-messages>
  <div class="form__down">
  <div class="form__group">
  <button (click)="sendMail(name.value, email.value, message.value)" [disabled]="angForm.pristine || angForm.invalid" class="form__input form__input--submit" name="submit" type="submit" value="SEND MESSAGE">SEND MESSAGE
  </button>
  </div>
  </div>
 
  </form>
const express = require('express');
 const router = express.Router();
 const request = require('request');
 const nodemailer = require('nodemailer');
 
 router.get('/send', (req, res) => {
  const outputData = `
  <p>You have a new contact request</p>
  <h3>Contact Details</h3>
  <ul> 
  <li>Name: ${req.body.name}</li>
  <li>Email: ${req.body.email}</li>
  </ul>
  <h3>Message</h3>
  <p>${req.body.message}</p>
  `;
 
  let transporter = nodemailer.createTransport({
  service: 'gmail',
  secure: false,
  port: 25,
  auth: {
  user: 'MY EMAIL',
  pass: 'THE PASSWORD'
  },
  tls: {
  rejectUnauthorized: false
  }
  });
 
  let HelperOptions = {
  from: '"MYNAME" <MYEMAIL,
  to: 'MYEMAIL',
  subject: 'Majeni Contact Request',
  text: 'Hello',
  html: outputData
  };
 
 
 
  transporter.sendMail(HelperOptions, (error, info) => {
  if (error) {
  return console.log(error);
  }
  console.log("The message was sent!");
  console.log(info);
  });
 
 });
 module.exports = router;
// server.js
 const express = require('express');
 const bodyParser = require('body-parser');
 const cors = require('cors');
 const path = require('path');
 const app = express();
 // Port Number
 const port = process.env.PORT || 3000
 // Run the app by serving the static files
 // in the dist directory
 app.use(express.static(path.join(__dirname, '/majeni/dist/majeni')));
 // Body Parser Middleware
 app.use(bodyParser.json());
 
 //routes
 const contact = require('./app/routes/contact');
 app.use('/contact', contact);
 // CORS Middleware
 app.use(cors());
 // If an incoming request uses
 // a protocol other than HTTPS,
 // redirect that request to the
 // same url but with HTTPS
 const forceSSL = function () {
  return function (req, res, next) {
  if (req.headers['x-forwarded-proto'] !== 'https') {
  return res.redirect(
  ['https://', req.get('Host'), req.url].join('')
  );
  }
  next();
  }
 }
 
 // Instruct the app
 // to use the forceSSL
 // middleware
 app.use(forceSSL());
 
 // For all GET requests, send back index.html
 // so that PathLocationStrategy can be used
 app.get('/*', function (req, res) {
  res.sendFile(path.join(__dirname + '/majeni/dist/majeni/index.html'));
 });
 
 // Start Server
 app.listen(port, () => {
  console.log('Server started on port '+port);
  });
import { Injectable } from '@angular/core';
 import { Headers, Http, Response } from '@angular/http';
 import { Jsonp } from '@angular/http';
 @Injectable({
  providedIn: 'root'
 })
 export class ContactService {
 
  constructor(private http: Http) { }
 
  sendEmail(name, email, message) {
  const uri = 'http://localhost:3000/contact/send';
  const obj = {
  name: name,
  email: email,
  message: message,
  };
  return this.http.post(uri, obj);
  }
 }

and

Failed to load resource: net::ERR_CONNECTION_REFUSED : :3000/contact/send:1

has occurred. I’ve checked the entire command line but still can’t find the mistake.

 

failed to load resource
  • 2 2 Answers
  • 634 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-06T10:27:51+00:00Added an answer on June 6, 2022 at 10:27 am

    The cause: 

    The reason of this error is that your client application isn’t able to connect with your nodejs servers.

    Solution: 

    Below code can help you resolve your problem effectively. You can refer it:

    const uri = 'http://localhost:3000/contact/send';

    If nodejs server on port 3000 is running on localhost, it will work.

     

    • 9
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Mia Jacquet
    2022-05-25T20:03:29+00:00Added an answer on May 25, 2022 at 8:03 pm

    This error is for anyone else. Verify that NodeJS isn’t crashing. This error can be caused by a previous request that causes the NodeJS server’s to crash or restart.

    • 17
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.