I have deployed my Nodejs Express app on GoDaddy using ssh access to configure the whole thing. But I can't find the URL that leads me to my app.
it works perfectly on my computer where I access the app via the link http://localhost:3000
const express = require("express");
const bodyParser = require("body-parser");
const httpRequest = require("request");
const app = new express();
const http = require("http").Server(app);
const io = require("socket.io")(http);
app.set("view engine","ejs");
var port = process.env.PORT || 3000;
app.use(express.static("public"));
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
//headers
app.use(function (req, res, next) {
// Website you wish to allow to connect
res.setHeader('Access-Control-Allow-Origin', '*');
// Request methods you wish to allow
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT,
PATCH, DELETE');
// Request headers you wish to allow
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
// Set to true if you need the website to include cookies in the requests sent
// to the API (e.g. in case you use sessions)
res.setHeader('Access-Control-Allow-Credentials', true);
// Pass to next layer of middleware
next();
});
app.get("/",(request,response)=>{
response.send("hello world!");
});
http.listen(port,function(){
console.log(server.address());
console.log("listening on port "+port);
});
I have the domain name of my server and I thought that adding ":3000" at the end of it will let me access the app but obviously it doesn't, I wanna know how to access it.
You might have to open the port first. The way you do it depends on what you use, with Linux-like OS and ufw you could do
sudo ufw allow 3000
You can find more information and docs here:
Use Ip address of your GoDaddy virtual machine. to find it follow the instruction below:
Usege:
http://youripaddress:3000
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.