Answer the question
In order to leave comments, you need to log in
How to make a POST request on my hosting?
There is a server that runs on my PC server.js:
const express = require("express");
const cors = require("cors");
const userRoutes = require("./routes/routes");
const app = express();
app.use(express.json());
app.use(cors());
app.use("/api", userRoutes); // /api/user/add
app.listen(process.env.PORT || 5000, () => {
console.log(`server is running on ${process.env.PORT || 5000} PORT`);
});
axios.post("http://localhost:5000/api/user/add", { ...values });
Answer the question
In order to leave comments, you need to log in
in process.env.PORT the port other than 5000 is accidentally not defined?
also try to write universal listening address in app.listen(port,'0.0.0.0',()=>...)
instead of localhost write 127.0.0.1
axios.post("localhost:5000/api/user/add", { ...values });localhost же, это не адрес твоей машины а локальный адрес где запущен код... пиши свой домашний ip, настраивай роутер на перенаправление внешних для него запросов внутрь локальной домашней сети и помни про российских провайдеров, которые создают случайные проблемы для поднятия серверов локально (например порт 8080 может не работать а к примеру 81 будет)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question