Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
node app.js returns undefined in console
I installed node and seems to work fine, but when i call a file it returns "undefined". What am I missing?
You normally get the response 'undefined' if you don't specify something to return in the function, 'undefined' is returned by default. Otherwise, the following will determine whether or not you are in the wrong directory:
1 Open up the terminal and create a file:
cat > test.js
2 Now enter some console log text in the file that you just created:
3 Save the file with 'Ctrl + D'
4 Now run the code:
If it works, then you are probably trying to run your other code from the wrong directory in the terminal.
I am in the right directory in terminal. npm and node is running. just installed it today. When I type: node test.js in terminal i get the message "undefined". So node is running but not in the right directory i suppose.
Aaron Martone3,290 Points
What is in your app.js? Is it a function? Does that function not explicitly return a value? Any function not given an explicit value to return will by default return