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

JavaScript Introduction to Programming Basics Writing Your Program

Running *.js file

how to run *.js file from console

2 Answers

Prabhu,

I would suggest letting node.js execute your javascript files.

Install node from here for your OS, http://nodejs.org/

Create your javascript file and from the console type: node myJavscript.js and hit enter.

hope this is helpful!

James Barnett
James Barnett
39,199 Points

This is an example of using a sledge hammer to kill a fly. For someone working on a badge entitled "Writing Your First Program" that's putting the cart way before the metaphorical horse.

You have a point that loading node.js just to execute a simple helloWorld.js file does seem overkill, but I have to ask the moderator since you made the point of criticizing my effort to assist another treehouse user.

Do you have a more accessible solution than running a quick installer and typing node myJs.js, in order to execute js files from the terminal?

James Barnett
James Barnett
39,199 Points

Joshua Rose -

Given the video that this question is related to writing your first program, I'm guessing the console alluded to by prabhu krishna is probably the JavaScript console built into the browser not a terminal.

To be honest, when I originally wrote my post I didn't think of the various way new people use the term "console". My guess is mostly based on my knowledge of the linked video although I can see where you are going.


> in order to execute js files from the terminal

install Spidermonkey it's JavaScript engine it will allow you to play with js directly from the terminal and also call js files from bash scripts, I've done something similar using jq to process JSON.

James Barnett
James Barnett
39,199 Points

Joshua Rose - It's just been pointed out to me there's coderunner on OS X, seems like it will do something similar. Not sure if it's actually scriptable or just an IDE with a built-in console.

Coderunner looks interesting, thanks for bringing that up!