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

General Discussion Preview Files in a Browser

Running a web project straight from VS Code?

I was wondering whether or not it's possible to run a project from VS Code, instead of copying the path and running in a web browser? When I attempt to run my project by clicking on "Run Without Debugging",it prompts me to select the environment.Once I select Node.js I get the following error message.

Cannot find runtime 'node' on PATH.Is 'node' installed?

4 Answers

Emre K.
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Emre K.
Full Stack JavaScript Techdegree Graduate 16,408 Points

Hello, Kasra,

Yes, it is definitely possible to run JavaScript exclusively on the terminal with Node. It might be that Node is not installed on your workstation just yet. The error message is indicating that it cannot find the runtime, Node.

I am going to provide you the link so you can pick the appropriate package for your Operating System (OS) https://nodejs.org/en/download

This portion is from Treehouse

Once you're in the file's directory, simply type node your-filename.js into the terminal and hit enter. Any output from your file will be displayed in the terminal.

Therefore, what I currently do (after making sure Node is installed) is right-clicking on the current JavaScript file in the file explorer sidebar in Visual Studio Code, and picking 'Open in Terminal' (it may be different depending on your OS), it will open up the terminal where you can simply type node yourJavaScriptFile.js to run it.

varlevi
varlevi
8,113 Points

While Emre Kayan's answer is valid, I don't think it is addressing your problem. If I'm not mistaken, I think that you're trying to run a website with html, css, and javascript in VS Code, as opposed to just javascript in the form of node.js, which is what Emre appears to be addressing in her answer. Unfortunately, I don't think there is a way to run a graphical website inside VS Code.

You will need to create a 'launch.json' file first. Please, see this link.