Friday 21 April 2017

Make Public Folder on node.js by express

I have an issue which I can't understand it;

I write an express server and want to make a public folder by that; Here is my code:

var app = express();
app.use("/public", express.static(path.join(__dirname, 'public')));
  var server = app.listen(constants.httpPort, function() {
    console.log("✔ Express server listening on port %d in %s mode", constants.httpPort, app.get('env'));
  });

I have a folder named "img" and there is some images at it;

I run this code on VPS, Ubuntu 14.04.5;

I log in my server Run app.js (it contains the express code) by PM2

 request ip:port/public/img/loading.gif  //It shows image

exit server

 request ip:port/public/img/loading.gif  //It shows message : Cannot
 GET /img/loading.gif

What happens when I exit from server? (I am sure the PM2 process is running)



via Fa.Shapouri

No comments:

Post a Comment