DEV Community

Cover image for How to run JS Code in VS Code
Raghavi Srinivasan
Raghavi Srinivasan

Posted on

4

How to run JS Code in VS Code

Hey all!Hope you all are doing well.

Usually we run the javascript code by linking it with HTML file and viewing output in browser.

In this blog post,let us see how to run Javascript code in Visual Studio Code.

  1. At first you need to install NodeJS in your Windows/Macbook. You can install it from here: https://nodejs.org/en/

2.

  • Create a new folder and open it in VS Code
  • Write the javascript code and name it with extension .js
  • After completing the code save the changes that you made

3.Open the terminal in VS Code.

Now , move to the current directory in which you are there using following command.

image1

You have moved to the directory in which your JS code is present.

4.Type the following command in VS code terminal to view the output of your code.

image2

Yes!!! That's it. By following the above steps you can view your output without the need of HTML file.

SurveyJS custom survey software

JavaScript UI Libraries for Surveys and Forms

SurveyJS lets you build a JSON-based form management system that integrates with any backend, giving you full control over your data and no user limits. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more.

Learn more

Top comments (4)

Collapse
 
oasirusleigon profile image
Domose Raphael

The node + filename method worked just fine for me. thanks a lot Raghavi Srinivasan

Collapse
 
vytautassugintas profile image
Vytautas Sugintas

FYI this won't work if you run js which uses browser specific APIs i.e.: window or document.

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal

Use deno.

Collapse
 
wisdomudo profile image
WISDOMUDO

Thanks so much, this was helpful.

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay