Setting Up Node.js and Visual Studio Code

Sep 2, 2024

Installing Node.js and Visual Studio Code

Downloading Node.js

  • Open a web browser and search for Node.js.
  • Click on the first link from nodejs.org.
  • Latest version (as of this video): 14.16.1 LTS
    • Recommended to choose the LTS version for stability.
  • Click on the 14.16.1 LTS option to download the MSI file.

Installing Node.js

  • Once downloaded, click on the MSI file to start the installation wizard.
  • Click Next, read the license agreement, and click Accept.
  • Leave the installation location as default unless changes are necessary.
  • Optional: Check the box to install tools for native modules (includes Chocolaty utility).
  • Click Next and then Install.
  • Confirm any prompts that appear during installation.
  • Wait for installation to finish; you will see a success message.
  • Click Finish to complete the installation.

Testing Node.js Installation

  • Open the Node.js command prompt or PowerShell.
  • Type node and press Enter to open Node REPL (Read, Evaluate, Print, Loop).
  • Test basic commands:
    • Example: console.log('Hello World');
    • Perform arithmetic operations or import modules.
  • To exit REPL, press Ctrl + C twice or type .exit.

Creating a Node.js File

  • Navigate to the desired folder.
  • Enable file name extensions in the view menu.
  • Right-click and create a new text document; rename it to hello.js.
  • Use a text editor to write Node.js code.
    • Example code to start a server on localhost:3000.
  • Save the file.
  • Open PowerShell or command prompt in the folder containing hello.js.
  • Run the file using: node hello.js.
  • Access the server in a browser at localhost:3000 to verify.

Installing Visual Studio Code

  • Search for Visual Studio Code in a web browser.
  • Click on the first link to code.visualstudio.com.
  • Download the executable file for installation.

Setting Up Visual Studio Code

  • Run the downloaded setup file.
  • Accept the agreement and proceed through the setup steps.
  • Customize options (create desktop icon, add context menu options, etc.) before installing.
  • Launch Visual Studio Code after installation.

Using Visual Studio Code for Node.js Development

  • Open a terminal in Visual Studio Code using Terminal > New Terminal.
  • You can increase font size using Ctrl + + and decrease with Ctrl + -.
  • Create and edit hello.js directly within Visual Studio Code.
  • Run Node.js code directly in the integrated terminal.

Visual Studio Code Features

  • Search and replace text across multiple files.
  • Integrated Git source control for tracking changes.
  • Built-in debugging support for Node.js.
  • Manage breakpoints and variable visualization during debugging.
  • Extensions support for additional functionalities (search for Node.js related extensions).

Conclusion

  • Successfully set up Node.js and Visual Studio Code for development.
  • Future videos will cover further coding and debugging practices.