Help with Node console

Help with Node console
0

#1

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!


#2

Hey guiKailu, so look to node as a js file. When you run a js file everything well be read?! Right? So if you put console.log as global it WILL appear on console!

So try the simple:

var express = require('express');
var app = express();


console.log('Hello World');

Share you app with FCC and will be done!

Remember, when you run ‘node app.js’ or ‘node server.js’ (Depends what do you use as main file), nodes will read. BUTTTTTTTTTT only will render if its on global or you access the route.

So if you use:
app.get(’/’, function(req, res){
res.send(‘Hello World’);
});

Hello Word will only send if you access the page ‘localhost:whatevertheportis/’.


#3

You just need to put the console log in the app.js or whatever the name is. It should work.

Edit: add it in myApp.js.


#4

Try to test something like:

app.get('/', function(req, res){
   console.log('Hello world")
});

Then run node and looks the console. Nothing? So try to access the localhost on your browser and then go back to the console! Now it will show

EDIT: This test is only to you know how Node works, please do it on your machine.


#5

Im quite sure the test will yell at him. The test will search for the console.log inside myApp.js.

Actually, there are comments to let you know where to place the code for each challenge.

/** 1) Meet the node console. */


#6

I meant to him to test on his machine. He cannot directly run the node on Glitch, just wait it runs.

But was my mistake to not be clear and make the misunderstanding, I used keywords like ‘run node’, ‘localhost’ but was not enough

Anyway, its a nice test to know how node works


#7

My fault. Didn’t read carefully :slight_smile:


#8

Oops! I was continuing to use the FCC boilerplate from the “Managing Packages with NPM” section. I didn’t realize that there’s a new glitch boilerplate for the “Basic Node and Express” section! :smirk: :laughing:

Perhaps this could be improved by saying, “Warning: This link to Glitch is a different link than in the previous section. This is a new project requiring this new link.” In case anyone else is as silly as me in the future… :yum: