Pre-requisites - Lab exercises
Use Personal Laptops
It's strongly recommended that you use personal laptop during exercises.
- Security , so you don't accidentally expose personal credentials (e.g. Github).
- Your code and changes might be wiped off on the lab computer.
Setup Github account and Git CLI
- 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
- Create Github repo from your account
- Using
git clone
command create local copy of the repository. -
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
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
- nvm - Linux/MacOS
- n - Linux/MacOS
- 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:
- Run
nvm i --lts
- Run
nvm use --lts
- You need to reload any old CLI windows such as Terminal (Linux) or Command Prompt/PowerShell (Windows)
- 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.
- To install on Windows or MacOS users download the LTS version from here and follow the steps throughout installer.
- For Linux distros you can use the respective package managers such as
apt
for Ubuntu.
Running your first Node.js program
- Download the following gist and save to file name
server.js
on your local machine. - Open a Terminal or Command Prompt/PowerShell CLI and navigate to the directory of the
server.js
file. - Execute
node server.js
with optional argument for port (e.g. in case 3001 is used, runnode server.js 3002
). You should get success message in your console"Hello World" Node Server running at http://127.0.0.1:3001
. - Open
http:127.0.0.1:3001
in your browser. You should see the following JSON response{ success: true, message: "Hello world!" }
Top comments (0)