JS-Replit
In a recent JS bootcamp course I was introduced to an online testing tool called replit . The interface was a little confusing at first, but I found a helpful video here. To save time, here are the steps outlined in the video for setting up a nodejs and python test environment.
Creating a nodejs replit
Steps:
– Create a free account in Replit https://replit.com/
– Click + Create Repl button (top left corner)
– Enter in Template field: blank > and click the Blank Repl item
– Enter Title: nix > and select the Create Repl button
– Select replit.nix in the left menu – this opens a file showing:
{ pkgs }: { deps = [ pkgs.cowsay ]; }
– Open a new browser window to https://search.nixos.org/packages
– enter nodejs > and select the nodejs-18x item > copy nodejs-18x from the terminal field:
nodejs-18_x
– Go back to the browser for replit.com > and replace the pkgs.cowsay with:
pkgs.nodejs-18_x
– In the left nav, click +file icon > name new file index.js > return
– In index.js type: console.log("Hello"); // hit return shows no results
– Left nav select .replit
– replace run = "cowsay Configure me!" with
run = "node index.js"
– Select Run button at top and now see "Hello" in right col console.
—————
Creating a Python replit:
(continuing from nodejs steps above)
– In left nav, click +file icon > name new file main.py > return
– In main.py type: print("Hello from Python")
– Open new browser window to https://search.nixos.org/packages
– enter "python" > select python38 > copy from terminal field:
python38
– Go back to browser for replit.com > Select left nav replit.nix
– Below pkgs.nodejs-18_x enter pkgs.python38
{ pkgs }: { deps = [ pkgs.nodejs-18_x pkgs.python38 ]; }
– In left nav, Select .replit >
– replace run = "node index.js" with
run = python main.py
– Select Run button at top and now see "Hello from Python" in right col console.
"Hello from Python"
—————
The nix app in replit also allows you to:
Run both python and js in same the repl
(continuing from steps above)
– in index.js replace console.log("Hello") with
const { exec } = require("child_process"); exec("python main.py", (error, stdout) => { console.log(error || stdout); console.log("Hello from Javascript") });
– in .replit change run = "python main.py" back to
run = "node index.js"
– Select run and now see
node index.js Hello from Python Hello from Javascript
The console is showing results for both JavaScript and Python