0

I am following this tutorial on Google Cloud Platform and am finding that the SIMPLE app launches successfully up on port 8080 but when I head over to the browser to view it externally, I get an internal server error. The tutorial can be found here: https://cloud.google.com/appengine/docs/standard/nodejs/building-app/deploying-web-service I am using Win8.1 using the GCP cloud shell terminal.

I have also tried updating my npm packages, moving my yaml, nodejs files to the next higher directory as well as deleting the package.json in the next higher directory. Like I said, port 8080 can come up and logged to the terminal, but does not come up in the browser. My package.json is as follows:

{
  "name": "express",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

My app.yaml file is

runtime: nodejs10

And my server.js file is

//this is a test by MP2
// date of use : 2020-0601
const express = require('express');
const app = express();

app.get('/', (req, res) => {
  res.send('Hello from App Engine!');
});

// Listen to the App Engine-specified port, or 8080 otherwise
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server listening on port ${PORT}...`);
});

Any help would be great since I am new to the google cloud. What is also interesting is that the most current version of express is installed at the next higher folder but not in the current one where the desired JSON is. ( and unable to update it) Thank you. -MP

Michael P
  • 13
  • 4

1 Answers1

0

It seems that this is because there is no express dependency in package.json:

"dependencies": {
    "express": "^4.17.1"
  }

I have replicated all steps and it worked. In the tutorial there is 4.16.3 version, I have different, because I have used npm install express -s and it added version automatically to package.json. However it works with 4.16.3 as well on my side.

I hope it will help!

vitooh
  • 4,132
  • 1
  • 5
  • 16
  • Hi Vltooh I run that command but nothing happens to my package.json file. I do not even get a progress bar when I am updating dependencies locally. I did try and run the website and got a '500 error', which is an internal server error again. I also use the command 'npm install --save express' which npm refused to install. That command was found here: https://cloud.google.com/nodejs/docs/setup – Michael P Jun 03 '20 at 22:53
  • Could it also have to do with this thread? https://stackoverflow.com/questions/12231846/npm-will-not-install-express – Michael P Jun 03 '20 at 23:14
  • I think `-s` option will only work when you install express for the first time. If you want to go trough the tutorial from the beginning you can use it. At this point, it should be possible to add the dependencies manually just by editing `package.json` with any text editor. – vitooh Jun 04 '20 at 06:14
  • @vltooh, This worked! Thank you very much for your help! I have also been working with other packages locally including hbs and fs locally. Since I will be installing these for the first time, the ```-s``` flag should work correct? – Michael P Jun 06 '20 at 14:25
  • @Micheal, the problem was in that there was no dependencies in the `package.json`, you can add them manually or add automatically during install with `-s` (which is shortcut to `--save` option) – vitooh Jun 15 '20 at 06:45