0

I install nodejs with express in server (subdirectory in ftp,path is /var/www/html/admin) and in admin folder i created file "app.js" which is working in xshell fine and showing message in console

here is my app.js

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

but now i want to show result in browser,how can i do this i tried with following urls but not working for me

http://myurl.com/admin:3000
http://myurl.com/3000/admin 
  • try in this: http://localhost:3000 if running in local machine, if its a server then : `http://:3000`, or like `http://myurl.com:3000` – Saikat Chakrabortty Jan 22 '19 at 08:38
  • @ i tried with http://myurl.com:3000 but not worked for me – Priya Jaiswal Jan 22 '19 at 08:44
  • where are you running? is it any server? or aws EC2? or local machine? – Saikat Chakrabortty Jan 22 '19 at 08:44
  • @saikatchakrabortty: i am running in server – Priya Jaiswal Jan 22 '19 at 08:55
  • can you add more info? like server IP, is it in aws or azure or something else? and also how you are running, also the output in the console after running? – Saikat Chakrabortty Jan 22 '19 at 09:02
  • This code looks fine. I think the problem is with the network access that you cannot access port 3000. Can we have more information about the server – Janith Jan 22 '19 at 09:11
  • @JanithKasun: server is aws – Priya Jaiswal Jan 22 '19 at 10:08
  • @saikatchakrabortty: because i am new in nodejs and i have ftp of aws server, in this server(root),there is site working (with nodejs+angular), now i want to create admin panel so i go to folder "var/www/html" and insert test.html(for test the url) then i open browser and write "myurl.com/test.html" , it worked fine so in same directory i install express and now i want to show in browser – Priya Jaiswal Jan 22 '19 at 10:13
  • well, in your case you need to login to that server through `ssh` , and there you have to run like this: `node app.js`, and before that you have to install `node.js` into that system. also, you have to open inbound port to `3000`, check this answer https://stackoverflow.com/questions/17161345/how-to-open-a-web-server-port-on-ec2-instance?answertab=votes#tab-top – Saikat Chakrabortty Jan 22 '19 at 10:31
  • @PriyaJaiswal have you configured a inbound rule? – Janith Jan 22 '19 at 16:27

2 Answers2

0

First get ip address of your FTP server.

Then connect http://<FTP_SERVER_URL:3000 to see 'Hello World' you wrote in the code.

To browse /admin folder you mentioned and if your express app is running on root directory, try http://<FTP_SERVER_URL:3000/var/www/html/admin

0

You can use document.write() method to write something to the DOM object( or in layman's language you can call it browser screen). Try using the following:

app.listen(port, () => document.write(`Example app listening on port ${port}!`))

Milad Bahmanabadi
  • 946
  • 11
  • 27
Harshit Agarwal
  • 2,308
  • 2
  • 15
  • 23