SDK
Node.js
Installation
Setup an example by making a directory:
mkdir hello-ngrok
Then, change to that directory:
cd hello-ngrok
Initialize your node project:
npm init -y
Install the ngrok package:
npm install @ngrok/ngrok
Now we need a runnable example. Let's create a new index file:
touch index.js
Put your app online
hello-ngrok/index.js
const http = require('http');
const ngrok = require('@ngrok/ngrok');
// Create webserver
http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end('Congrats you have created an ngrok web server');
}).listen(8080, () => console.log('Node.js web server at 8080 is running...'));
// Get your endpoint online
ngrok.connect({ addr: 8080, authtoken_from_env: true })
.then(listener => console.log(`Ingress established at: ${listener.url()}`));
Run your NodeJS app with your ngrok authtoken as an environment variable. Sign up for a free account to get your authtoken.
NGROK_AUTHTOKEN= node index.js