DEV Community

Cover image for Node.js Dev Environment Setup
Georgi Kotov
Georgi Kotov

Posted on • Updated on

Node.js Dev Environment Setup

Pre-requisites - Lab exercises

Use Personal Laptops

It's strongly recommended that you use personal laptop during exercises.

  1. Security , so you don't accidentally expose personal credentials (e.g. Github).
  2. Your code and changes might be wiped off on the lab computer.

Setup Github account and Git CLI

  1. Setup a Github account beforehand and install Git CLI following the instructions and login to the CLI with your Github account.

Easiest way to do that is to

  1. Create Github repo from your account
  2. Using git clone command create local copy of the repository.
  3. Create some dummy.txt file and run the following commands:

    git add -u dummy.txt
    git commit -m "feat(dummy): my cool dummy commit"
    git push -u origin main
    
  4. Verify changes are pushed to your Github repo.


Installing IDE

I strongly recommend installing Visual Studio Code due to the wide community and support, as well as for the amazing plugins. Unless you are not used to use something else for Node like Webstorm, Sublime or other go with VS Code.

Kind request: Do everyone a favour and please use dark theme on your IDE.

Node Version Manager (Optional)

It's sometimes required to be able to toggle between different versions of Node due to dependencies or project specific requirements hence use version manager.

Libraries

Installation and verification with NVM

After installing the CLI, make sure you install and use the LTS version of Node (currently 16.18).

With nvm you do that by the following:

  1. Run nvm i --lts
  2. Run nvm use --lts
  3. You need to reload any old CLI windows such as Terminal (Linux) or Command Prompt/PowerShell (Windows)
  4. Open a new Terminal or Command Prompt and run node -v you should get the lates node version printed out.

Node Installation (Simple)

You can install Node.js without NVM using plain installation.

  1. To install on Windows or MacOS users download the LTS version from here and follow the steps throughout installer.
  2. For Linux distros you can use the respective package managers such as apt for Ubuntu.

Running your first Node.js program

  1. Download the following gist and save to file name server.js on your local machine.
  2. Open a Terminal or Command Prompt/PowerShell CLI and navigate to the directory of the server.js file.
  3. Execute node server.js with optional argument for port (e.g. in case 3001 is used, run node server.js 3002). You should get success message in your console "Hello World" Node Server running at http://127.0.0.1:3001.
  4. Open http:127.0.0.1:3001 in your browser. You should see the following JSON response { success: true, message: "Hello world!" }

Congrats you are a Web Developer now! The rest is copy-pasting from StackOverflow!

congrats

Top comments (0)