Help in making GET requests in Digital Ocean Node droplet and remote development?

Hey guys,

I’m having difficulty making GET requests and I’m not sure if it’s my code or maybe I didn’t setup my remote development correctly. I’m using Digital Ocean Node.js droplet “This droplet is all set up with NodeJS, PM2 for process management, and nginx.”

I keep getting a 404 in POSTMAN when I do a GET request to my ip address and when I go to the browser to my ip address/api/posts it says the page can’t be found.

server.js

require('dotenv').config()
const express = require('express')
const mongoose = require('mongoose');
const path = require('path');

const app = express()

const postsApi = require('./api/postsApi');



mongoose.connect
    (process.env.DB_URI, {
        useNewUrlParser: true,
        useUnifiedTopology: true
    }).then(() => {

        app.listen(process.env.PORT, () => {
            console.log('Listening to port 5000!')
        })

    })


//POST form handling
app.use(express.json());
app.use(express.urlencoded({ extended: true }));

//Routing
//app.use('*', express.static(path.join(__dirname, '../public/index.html')));
app.use(express.static(path.join(__dirname, 'public')));
//app.use(express.static(path.resolve(__dirname, '../client/build')));

app.use('/api/posts', postsApi);

postsAPI

const fs = require('fs');
const path = require('path');
let express = require('express');
let router = express.Router();
const postsController = require('../controllers/postsController');
const PostService = postsController.PostService;


// routing code

// list
router.get('/allPosts', (req, res, next) => {
    PostService.list()
        .then((posts) => {
            console.log(`API: Found posts: ${posts}`);
            res.status(200);
            res.json(posts);
        }).catch((err) => {
            res.status(404);
            res.end();
        });
});




// export our router
module.exports = router;

postsController

const Post = require('../models/postSchema');



class PostService {
    //  list
    static list() {
        return Post.find({})
            .then((posts) => {
                return posts;
            });
    }
    //  findOne
    static find(id) {
        return Post.findById(id)
            .then((post) => {
                return post;
            });
    }
    //  create
    static create(obj) {
        var post = new Post(obj);
        return post.save();
    }

    //  update
    static update(id, data) {
        return Post.findById(id)
            .then((post) => {
                post.set(data);
                post.save();
                return post;
            });
    }

    //  delete
    static delete(id) {
        return Post.deleteOne({ _id: id })
            .then((obj) => {
                return obj;
            })
    }
}


module.exports.PostService = PostService;

postsSchema

const mongoose = require("mongoose");


const Schema = mongoose.Schema;
let postSchema = new Schema({
    title: { type: String, minLength: 5, required: true },
    post: { type: String, minLength: 5, required: true }
});


module.exports = mongoose.model("Post", postSchema);

Issue solved. I had to restart with pm2. pm2 restart <myfile>