0

express.js code runs on local machine but not on aws-cloud9 IDE preview

I am new to express.js and AWS-cloud9 IDE, both. I am trying to run following code on AWS-cloud9 IDE. I get proper output on terminal, but no/error output on the preview browser.

const express = require('express');
const data = require('./data/data.json');

const app = express();
const PORT = 3000;

app.get('/', (req, res) => {
    res.send(`a GET response for / on port ${PORT}.`);
});

app.listen(3000, () => {
    console.log(`server started on port ${PORT}`);
    //console.log(data);
});

Expected output:

a GET response for / on port 3000.

Actual output:

Cannot GET /vfs/c6f5fa76bfff441c9dbcaa02d4c81a14/previewlocalhost:3000/
abdusco
  • 9,700
  • 2
  • 27
  • 44
  • How are you calling your endpoint when it's on AWS? I assume locally you're going to `localhost:3000` but how are you doing that when it's on Cloud9? – rb612 Jul 18 '19 at 06:30
  • Yes, I made this mistake, as I wasn't aware of how cloud9 preview works. I thought as it it a VM, it should run in similar way. This issue is resolved now. I was trying to run 'localhost:' on AWS-cloud9 IDE, instead of previewing running script, hence the issue. – Aditya Lodha Jul 19 '19 at 17:16

0 Answers0