Just spent 1.5 hours trying to pass the test on the Node console challenge, which asks you to write “Hello World” to the console.
The challenge just says that nodejs is like js, except that it prints to the terminal, or in Glitch’s case to the Glitch console, instead of to the Browser Console. To me, that means, I need to use console.log("Hello World")
and look for the hello world message in the glitch console.
But it doesn’t say where in the project structure to write that one line of code. I tried writing it between script tags in the index.html tag, the way I might place regular js code. That got it to print in the browser’s dev tools.
Then I tried a few solutions that did get “Hello World” to show in the glitch log (instead of the browser’s dev tools) in multiple ways, but none of them passed the fcc tests.
I included an additional "start": "node app.js",
script in package.json, after the "start": "node server.js"
. The app.js had the console.log("Hello World")
line in it. That did show hello world in the glitch log but caused a time-out in the live version of the app. I tried placing that start
script before and after
I also was able to get it to show in the glitch log by adding it in the app.listen function in the server.js file. That, however, resulted in the fcc verification to say “Not Found” in its test.
I tried including "post-start": "node app.js"
in the package.json. With console.log("Hello World"
in that app.js file. That didn’t cause the timing-out error, but it also didn’t show “Hello World.”
I tried including
var express = require('express');
var app = express();
app.get('/', function(req, res){
res.send('Hello World');
});
app.listen(3000);
in that app.js file runnning on post-start.
The “Managing packages with npm” challenges included such baby-steps throughout that it took me less than an hour and I feel confident about that material, but challenge number 1 in this next section has got me stumped. Thanks for any help!