ckportfolio.com - Launching Terminal via Visual Studio Code

Launching Terminal via Visual Studio Code

Command Line Interface

While GUI (graphical user interface), thanks to the proliferation of Windows and macOS, has long dominated the personal computing market, its precursor CLI (command line interface) never went away. Though hidden away deep in each operating system, CLIs are essential in further diagnosing, configuring, and customizing the system to the needs of each "power user."

As web development becomes more accessible, CLIs are making a comeback: instead of spending a considerable amount of time to build a dedicated GUI, engineers quickly can put together a simple interface accessible using a keyboard, and developers are eager to jump onboard and endure a brief learning curve to take advantage of new technologies with speed and precision. At this point, CLIs are a default choice for any budding programmer.

Getting Started

Based on two distinct core engines, Windows and macOS offer different CLI experiences. Acknowledging that Linux is the most popular operating system of choice, Visual Studio Code offers a cross-platform terminal that provides a consistent experience for both systems.

We can start by creating a dedicated project folder and uploading a single JavaScript file (main.js) that will be launched by Node.js. While it is difficult to imagine how JavaScript code can be launched outside of the web browser, we can later confirm this using the terminal:

main.js

console.log("We can now use JS to control the server!");

Upon confirming that the file has been successfully uploaded, we can launch a terminal by right clicking on the folder:

A new tab opens below the open main.js window, and we can log into ocad.ckprototype.com to directly interact with the server content using the following command:

Terminal Command

ssh ocad@ocad.ckprototype.com

Providing the correct password (available in .vscode and other tutorial pages) and optionally consenting to connect to the new host, the ocad.ckprototype.com welcomes us rather plainly:

Launching Node.js

By default, the logged-in user starts the experience in the /public folder, much like logging into the SFTP server with FileZilla. In fact, SFTP stands for "SSH File Transfer Protocol," and using FileZilla is to use the very same ssh command for the purpose of transferring files.

We can verify the location by using the ls command to display the current folder list:

Terminal Command

ls

Upon seeing the sea of names, we can travel to the dedicated project folder using cd and verify that the main.js file exists in the folder:

Terminal Command

cd {foldername}
ls

Finally, we can use the node command to launch Node.js to compile main.js. Should this be successful, the server will interpret our sample code, and display the text "We can now use JS to control the server" on screen:

Terminal Command

node main.js

The terminal correctly displays the message, and we can now move onto further experimenting with other basic lines of JavaScript code (ex. variables and simple arithmetics) and enabling browser automation.

Fin