I have one post() and get() request in Express JS. My post() request is not working in local machine.It is throwing 404 error and message "Cannot POST /sendMessages/" .However, when I deploy the app to the firebase cloud function and tested the requests both are working perfect. So, every time when I made changes I had to deploy and then test which is a tedious task.
const functions = require("firebase-functions");
const express = require('express');
var bodyParser = require('body-parser');
var cors = require('cors')
const PORT = 3000;
const app = express()
app.use(express.json())
app.use(cors())
app.get('/hello', (req, res, next) => {
res.send('Welcome')
})
app.post('/sendMessages', (req, res) => {
console.log(req.body)
res.json({ 'status': 'Success' })
})
app.listen(PORT, () => {
console.log("Server is running on port, " + PORT)
})
exports.app = functions.https.onRequest(app)
Can anyone please tell me what's the issue. Thanks in advance.
Finally, I figured out what silly mistake I have been doing all these days. I was running my nodemon start on normal folder rather than functions folder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.