Node.js Dev Environment Setup
Tags: webdev, node, beginners, programming
Published: 2022-10-17 15:57:21

## 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](https://github.com) beforehand and install Git CLI following the [instructions](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and login to the CLI with your Github account.

Easiest way to do that is to
1. Create Github repo from your account
1. Using `git clone` command create local copy of the repository.
1. 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
1. Verify changes are pushed to your Github repo.



---


## Installing IDE

I strongly recommend installing [Visual Studio Code](https://code.visualstudio.com/download) 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

- [nvm](https://github.com/nvm-sh/nvm) - Linux/MacOS
- [n](https://github.com/tj/n) - Linux/MacOS
- [nvm-windows](https://github.com/coreybutler/nvm-windows) - used for Windows


### 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`
1. Run `nvm use --lts`
1. You need to reload any old CLI windows such as Terminal (Linux) or Command Prompt/PowerShell (Windows)
1. 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] (https://nodejs.org/en/) and follow the steps throughout installer.
1. 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](https://gist.github.com/MrKotov/3690757b95ba93a8b79744f58b800b9b) and save to file name `server.js` on your local machine.
1. Open a Terminal or Command Prompt/PowerShell CLI and navigate to the directory of the `server.js` file.
1. 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`.
1. 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pmbmesauyezgs2vl521b.png)