URL Shortener Microservice

i do not understand what the problem is? it is not redirecting to a correct page.any help,thanks in advance.

const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const dns = require('dns');
const urlparser = require('url');
const cors = require('cors');
const app = express();

// Basic Configuration
const port = process.env.PORT || 3000;
mongoose.connect(process.env.DB_URI,{ useNewUrlParser: true, useUnifiedTopology: true });

app.use(bodyParser.urlencoded({extended: false}));
app.use('/public', express.static(`${process.cwd()}/public`));

let schema = new mongoose.Schema({url: String,shorturl: Number});
let Url = mongoose.model("Url",schema);

app.get('/', (req, res) => {
  res.sendFile(process.cwd() + '/views/index.html');

// Your first API endpoint
app.post('/api/shorturl', (req, res) => {
const bodyurl = req.body.url;
const checkaddress = dns.lookup(urlparser.parse(bodyurl).hostname,(err,address) => {
      res.json({error: 'invalid url'})
      let shortUrl = Math.floor(Math.random() * 100000); 
      const url = new Url({url: bodyurl,shorturl: shortUrl});
      url.save((err,data) => {
        if(err) return console.log(err);
        res.json({ original_url : data.url, short_url : data.shorturl})

app.get('/api/shorturl/:shortUrl',(req,res) => {
  let shortURL = req.params.shortUrl;
  Url.find({short_url: shortURL},(err,data) => {
      res.json({ error: 'invalid url' })

app.listen(port, function() {
  console.log(`Listening on port ${port}`);

First, set this up as a repl (like on replit.com) to make it easier for people to run and debug.

Second, you need to add logging statements to actually determine what is happening with the code. At a minimum, you need to log which route is running, what the route inputs are, and what the route outputs are at every point a response is returned to every route. You’ve got some log messages, but not nearly enough to track the state of the code as it executes.

Especially helpful would be logging (all) the data you’re using here

since I don’t think it’s what you think it is. Doing this will also give you a suitable alternative to using a small random number for the shortened URL as mongoDB provides a solution.

Further, this

returns the return value of console.log() and not the error.

finally after taking a break,i understand the problem and it was ,i used a wrong key in the find method which is short_url but from the schema as you can see it was shorturl and also i should be using findOne not find,since it returns an array.
yes of course you are right loging to the console helps a lot,thanks.and i already set up in repl.i was thinking using the id from the mongoose but it is huge and does not argue with short url i think.