Create your Node.js Application
In this step, you will create a simple Node.js application. You will use an application generator to quickly scaffold out the application from a terminal.
Install Node.js and npm
From the integrated terminal (⌃` (Windows, Linux Ctrl+`)), install Node.js and npm, the Node.js package manager.
sudo apt-get install nodejs npm
You can verify the installations by running:
node --version npm --version
Install the Express Generator
Express is a popular framework for building and running Node.js applications. You can scaffold (create) a new Express application using the Express Generator tool. The Express Generator is shipped as an npm module and installed by using the npm command-line tool
sudo npm install -g express-generator
-g switch installs the Express Generator globally on your machine so you can run it from anywhere.
Scaffold a New Application
You can now scaffold a new Express application called
myExpressApp by running:
express myExpressApp --view pug
--view pug parameters tell the generator to use the pug template engine.
To install all of the application's dependencies, go to the new folder and run
cd myExpressApp npm install
Run the Application
Last, let's ensure that the application runs. From the terminal, start the application using the
npm start command to start the server.
The Express app by default runs on http://localhost:3000. You won't see anything in your local browser on localhost:3000 because the web app is running on your virtual machine.
To be able to browse to the web app on your local machine, you can leverage another feature called Port forwarding.
To be able to access a port on the remote machine that may not be publicly exposed, you need to establish a connection or a tunnel between a port on your local machine and the server. With the app still running, open the SSH Explorer and find the Forwarded Ports view. Click on the Forward a port link and indicate that you want to forward port 3000:
Name the connection "browser":
The server will now forward traffic on port 3000 to your local machine. When you browse to http://localhost:3000, you see the running web app.