For reference this repo contains a sample code (clone, install npm run server).
This is my server.js
const express = require('express');
const app = express();
app.get('/', (req, res) => res.send('Hello World!'));
app.post('/', (req, res) => res.send('Got a POST request'));
app.put('/', (req, res) => res.send('Got a PUT request at /'));
app.delete('/', (req, res) => res.send('Got a DELETE request at /user'));
const PORT = process.env.PORT || 5000;
app.listen(PORT, () => console.log(`Listening on ${PORT}`));
When I run locally npm run server and test with Postman I get the correct strings when calling the respective method (GET / => 'Hello World!', POST / => 'Got a POST request', and so on.
Then I have a Ubuntu droplet in DigitalOcean that I:
- Created a user
apt-get updateanddit-upgrade- Installed node
v12.16.1with npm6.13.4andgit - Then
git clone git@github.com:Kmelow/route-bug.git(this is repo where my code is) cd,npm installandnpm start
Next, I used Postman to test using the new URL.
Then, if I do a GET, POST, PUT, DELETE or any other method I always get Hello World!.
I can't understand why. What I'm doing wrong?