Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
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