Kan bron niet laden: net::ERR_CONNECTION_REFUSED : Nodejs

Ik heb een bootstrap-formulier voor e-mailservices voor de app angular 6en nodejs, ik gebruik nodemailervoor sendemail in mijn app, werkt helaas niet. Ik krijg de volgende foutmelding:

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

hier is het formulier

<form [formGroup]="angForm" novalidate>
    <div class="message">
      <h3> Write to us </h3>
    <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 *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 class="form__group">
          <input class="form__input form__input--email" type="email"  formControlName="email" placeholder="email" #email>
        <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 class="form__right">
        <div class="form__group">
          <textarea class="form__input form__input--textarea" placeholder="Message" formControlName="message"  #message
        <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 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

Hier is contact,js (node ​​mailer instellingen en routes)

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>
      <li>Name: ${req.body.name}</li>
      <li>Email: ${req.body.email}</li>
    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!");
module.exports = router;

hier is de server js.

// 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
const contact = require('./app/routes/contact');
app.use('/contact', contact);
// CORS Middleware
// 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('')
// Instruct the app
// to use the forceSSL
// middleware
// 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);


Hier is service

import { Injectable } from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import { Jsonp } from '@angular/http';
  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);

Wat ontbreekt er in mijn code?

Antwoord 1, autoriteit 100%

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

Uw fout betekent dat uw clienttoepassing geen verbinding kan maken met uw nodejs-server.


Uw code:

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

Werkt als de nodejs-server op poort 3000 op localhost draait.


Please enter your comment!
Please enter your name here

Other episodes