Console log to terminal
termlog send the browser console log to your terminal
It also comes with a nodejs REPL so you can do some basic draft code
- While you developing your front-end app and you have to switch back and forth between IDE and browser
- When you test app on mobile and need to check log. (See Debug on mobile)
There are 2 ways and it depends on your preferences
- Install the
termlog
binary :npm install --save-dev termlog
( you also can install globally withnpm install -g termlog
) - Start server
npx termlog
ortermlog
if you install globally - Go to the entry file of your project (I.e: app.jsx for React or main.js for Vue)
- Insert these two lines:
import termlog from "termlog"
termlog()
- You should now see log being streamed to your terminal
Note: with this approach you might want to remove two lines above in production
By default termlog will not run if it detects production mode using NODE_ENV
, but you shouldn't rely on that
- Install the
termlog
binary :npm install -g termlog
- Start server
termlog
- Go to your browser and open the console window
- Copy code inside index.js file without the last export line into console
- Enter
termlog()
into console - You should now see log being streamed to your terminal
Note: with this approach you have to do all steps 3-6 every-time you refresh your browser tab
With termlog
command:
--out path
: Save log to file--port port
: Change server port--addr addr
: Change server address--show levels
: Select log levels to display (info | warning | error | debug). Multiple levels are seperated by,
use
.show levels
while the server running to select again
With termlog
package:
termlog({ host: "localhost", port: 3456 })
To be able to stream log from your app running on mobile you need to:
- Start term log with
0.0.0.0
by runningnpx termlog --addr 0.0.0.0
- Find your private IP address
- MacOS: run
ipconfig getifaddr en0
if you're on wifi and - Linux: run
hostname -I
- Windows: run
ipconfig
and find in the printed result. It should be under192.168.x.x
- MacOS: run
- Inside your project init tconfig with:
termlog({host: "YOUR_PRIVATE_IP"})
Termlog have 2 components:
- server.js - a websocket server to receive log message and display on terminal.
- index.js - termlog function to override default behavior of
console
object by capture arguments and send to websocket server
- Install using
<script/>
tag - (Maybe) An extension to start termlog on browser so we don't have to install dependencies
- (If possible) Browser console REPL instead of nodejs REPL