Gold medal project - solution code not rendering on localhost

https://www.codecademy.com/paths/web-development/tracks/sql-for-web-development/modules/project-gold-medal-metrics/informationals/bapi-p5-gold-medal-metrics

Following instructions after running solution code.

The server runs fine on port 3001.

Opening localhost:3001 shows ‘Cannot GET /’ but not rendering the app.

Does the solution code render for anyone?

2 Likes

This took me a while to figure out and there’s probably a better way.

In server.js, I added:
app.use(express.static('public'); //line 13 below the CORS expression

I then made a new folder called /public

Then I moved /build, /css, /img, index.html, and index.js into the /public folder.

Open the recently moved index.js and add a period to the app import so it goes up one level:

import App from '../App'; // replace line 3

Reload the server, open localhost:3001, and it worked!

2 Likes

I’m getting some weird messages when trying to install webpack. Codecademy needs to keep the project file and dependencies updated.

1 Like

It will work if you simply add this line to server.js, globally scoped and after the ‘app’ declaration:

app.use(express.static(__dirname + '/'));

Works neither way. I guess not many people are actually hitting this project, so Codecademy doesn’t bother with making a video or something more explanatory. I think it’s a simple bug somewhere, but due to the lack of node.js knowledge it is a wall for a beginner.

It’s a pitty. Not a bad course in general…

I had to change the modules.exports.module method in the webpack.config.js file.

module: {

      rules: [

          {

              test: /\.js$/,

              loader: 'babel-loader',

              query: {

                  presets: ['es2015', 'react']

              }

          }

      ]

  }

i changed the loader property to rules as i had a look on at the webpack js website and under the loaders section example they we using a rules property rather than loader.

This solution worked for me, I am surprised this issue has not been formally addressed by course organisers. As user giga0618705211 suggested this is a wall for beginners and perhaps deserves a some formal attention.

1 Like