简体   繁体   中英

What is the url with which I can access my expess app (nodejs)

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:

ufw - Uncomplicated Firewall

Use Ip address of your GoDaddy virtual machine. to find it follow the instruction below:

  1. Log in to your GoDaddy account.
  2. In your My Products page, click Servers.
  3. Next to the server you want to use, click Manage. The server IP address appears in the
  4. Details tab. You may need to scroll down to see the address in the list.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM