NodeJS using Express, Error: getaddrinfo ENOTFOUND https

  api, express, https, javascript, node.js

I have test with different solution but still error. I ran my code (backend) on Heroku, and I tested it with Postman.
Error is show like this

Error: getaddrinfo ENOTFOUND https

This is the app.js

const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')

const paketRoutes = require('./routes/paket-routes')
const transaksiRoutes = require('./routes/transaksi-routes')
const laporanRoutes = require('./routes/laporan-routes')
const HttpError = require('./models/http-error')

const app = express()

const PORT = process.env.PORT || 5000

app.use(express.json())

app.use((req, res, next) => {
    res.setHeader('Access-Control-Allow-Origin', '*')
    res.setHeader('Access-Control-Allow-Headers', 'Origin, X-Request-With, Content-Type, Accept, Authorization')
    res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PATCH, DELETE')
    next()
})

app.get('/', (req, res) => {
    res.send('Halo')
})
app.use({
    host:'ameera-laundry.herokuapp.com',
    path:'/paket'
}, paketRoutes)
app.use('/transaksi',transaksiRoutes)
app.use('/laporan', laporanRoutes)

app.use((req, res, next) => {
    const error = new HttpError('Could not find this route', 404)
    throw error
})

app.use((error, req, res, next) => {
    if(res.headerSent) {
        return next(error)
    }
    res.status(error.code || 500)
    res.json({message: error.message || 'an unknown error occured'})
})

mongoose
    .connect('mongodb+srv://name:[email protected]/task?retryWrites=true&w=majority')
    .then(() => {
        app.listen(PORT)
    })
    .catch(err => {
        console.log(err)
    })

I test with 1 api using host and path, but still fail. Please help, I cant find another solution, Newbie here.
Thanks for the answer and solution, help me a lot.

Source: Ask Javascript Questions

LEAVE A COMMENT