How can Ngrok help me expose my local server worldwide?
Tags: codernadir, nestjs, tutorial, ngrok
Published: 2024-04-11 10:39:12

_**Hi, this is CoderNadir in another post where I'll share with you how to expose your local server to the world!**_

**What do I mean by exposing it to the world?**
I mean share a link to anyone by running a (Node/Nestjs/...) server in your local machine!

**The question now is how?**
Simply by the help of _[Ngrok](https://ngrok.com)_

For this tutorial let me explain to you what is Ngrok based on what we'll use it for, and if you want to read more about it then follow this link:
 _[Ngrok overview](https://ngrok.com/docs)_

You can think of Ngrok like a hosting service where you can put your app and it will be public for access by anyone, but not really 😒. so keep reading and you'll get the idea clearly!

**Note:** it's only free for non-commercial use. see _[pricing](https://ngrok.com/pricing)_
_In this tutorial I'll be using Windows 11 as OS_

**Now let's jump into the important part from this tutorial!**

**1-** Create an account _[here](https://dashboard.ngrok.com/signup)_.
**2-** Chose your OS and download the ZIP folder!
![Zip File](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v22thm8zkp9n9cjv7u3m.png)
**3-** Go to your downloads and extract the zip file! once you'll extract it, you'll be popped up by a window asking you where you want to extract the file! remove the path and paste this:
`C:\ngrok`
Now to navigate to that extracted file we should go to:
`C:\ngrok` and you'll find this file:

![Extracted File](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qj6dzfuu6hsdic6esyjn.png)

Now if you double click this file you'll open a Ngrok window with some details:

![ngrok cmd window details ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xncamsk0ospesbf054vl.png)

You've made it right! (really 😒) not yet!

**4-** Now we want to be able to run ngrok commands from the command line without the need to navigate to app folder and run it, therefore we'll need to set up the system environment.

Search `Edit the system environment variables` in your settings and open it!

![Edit the system environment variables](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6cigwgntopo9ngmzfde3.png)

Then click:

![CoderNadir](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/35l31g3ed7g8n2l7guhx.png)

Next, Select `Path` and click `edit`


![CoderNadir](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1oaaf5vgo40l78bktfg1.png)


Click `New` then paste the path to your ngrok app in our case it's `C:\ngrok` then close all the opened windows by clicking `ok` button


![CoderNadir tutorial for ngrok installation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9uhbjw1wryoauxq9plx8.png)


Now you can use ngrok from the command line, so open it and type: `ngrok` and it should open a Ngrok window with some details!

**Note** if you want to test it in your Code Editor like (VSCode) you might need to close it and open it or even restart the PC!

We need another configuration before start using it, so hang on there 😀

Go to your ngrok -[dashboard](https://dashboard.ngrok.com/get-started/your-authtoken)_ and under the section:
_`Getting started`_ => _`Your Authtoken`_ 
copy your authentication token, paste it in the command line and hit enter, Command:
`ngrok config add-authtoken <YOUR_AUTH_TOKEN>`

Hooray! now we can start using it 🥳

I'll assume that you already have a local server running, let's say on port `3000`, cool!

**5-** Now running the server with Ngrok
Your ngrok command should be:
`ngrok http 3000`

You'll see some details about your server, let's say your online app 😉
(`1` is your public URL server, `2` is your forwarded local server)

![ngrok server tutorial by CoderNadir](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gko6lhphq54wwzzvjbjk.png)

**AND BOOM 🚀 Now you know how to expose your local server to the world! 🥳**

**BUT HOLD ON!**
**WHAT IF YOU WANT TO ALSO EXPOSE YOUR DATABASE? 🤔**
_remember that your account is free and you're limited to only one forwarded server!_

Let me know in the comments below if I should create the second part without the need to pay! 😉🤑

Catch you next time! (second part 😅)