Vintage nautical HarborClient badge illustration with lighthouse and Express Echo ribbon

Local API work often means juggling a terminal for Node, a browser for the server URL, and an API client for requests. HarborClient Live Servers can keep that loop in one place: start a companion Express process with Run command, forward traffic with reverse proxy rules, and store the Live Server URL in a global variable your collection can reuse.

This tutorial builds a tiny Express echo server on port 3000, wires it into HarborClient, creates an Echo collection with GET, POST, PUT, and DELETE requests, then sends each request and runs the whole collection.

Getting Started

You will need the following:

Create the Express echo server

In a new folder, initialize a Node project and install Express. In this example I’m going to create the server folder in /home/sean/echo-server.

cd /home/sean
mkdir echo-server
cd echo-server
npm init -y
npm install express@5

Create server.js. The app listens on port 3000, accepts any method and path, and echoes the request details as JSON with an application/json response:

const express = require('express');

const app = express();
const PORT = 3000;

app.use(express.json({ limit: '1mb' }));
app.use(express.urlencoded({ extended: true }));

app.all('/{*path}', (req, res) => {
  res.type('application/json').json({
    method: req.method,
    url: req.originalUrl,
    path: req.path,
    query: req.query,
    headers: req.headers,
    body: req.body
  });
});

app.listen(PORT, '127.0.0.1', () => {
  console.log(`Echo server listening on http://127.0.0.1:${PORT}`);
});

You can smoke-test it once from a terminal with node ./server.js, then stop it. HarborClient will start the process for you in the next step.

Create a Live Server for Express

Open the Servers rail and click New Live Server (or choose File → New Live Server). In the footer panel:

  • Name — Echo Server
  • Variable — echo_server_base. HarborClient sets this global to the Live Server origin when the server starts.
  • Root directory — the echo-server folder you created (use Browse).
  • Run command — an absolute Node binary plus your script, for example /usr/bin/node /home/sean/echo-server/server.js. The working directory is the root directory, and HarborClient does not run a shell, so keep the command simple.
  • Optional: enable Restart on crash so HarborClient restarts the companion process after an unexpected exit.
HarborClient Edit Live Server panel with General Headers Routing Proxy Aliases CORS and SSL tabs
Configure the Live Server name, root folder, port, and related options in Edit Live Server.

Open the Proxy tab and click Add rule:

  • Path — * (catch-all; HarborClient stores this as /)
  • Target URL — http://localhost:3000
  • Leave Enabled checked. For a catch-all path, strip path is a no-op and the full request path is forwarded to Express.
HarborClient Live Server Proxy tab for reverse proxy rules that run before local file serving
Add reverse proxy rules so API traffic can forward to your Express process.

Click Save. When you start the Live Server later, HarborClient listens on its own loopback origin (often from port 5500 upward), starts Express with the run command, and proxies every path to port 3000.

Create the Echo collection

Switch to the Collections rail and create a collection named Echo (File → New Collection, or the section +). From the collection row menu, choose New → New Request four times and configure:

  • GET Echo — method GET, URL “{{echo_server_base}}/get“
  • POST Echo — method POST, URL “{{echo_server_base}}/post“
  • PUT Echo — method PUT, URL “{{echo_server_base}}/put“
  • DELETE Echo — method DELETE, URL “{{echo_server_base}}/delete“
HarborClient Echo collection with GET POST PUT and DELETE requests using {{echo_server_base}} URLs
Point collection requests at {{echo_server_base}} after the Live Server variable is set.

For POST Echo and PUT Echo, open the Body tab, choose JSON, and add a sample payload. HarborClient sets Content-Type: application/json automatically for JSON bodies unless you already set that header.

{
  "message": "hello from HarborClient",
  "source": "echo-collection"
}

Save each request. The {{echo_server_base}} placeholder resolves from the global variable Live Server sets on start, so the URLs stay portable even when the Live Server port changes.

Start the server and test the endpoints

In the Servers rail, start Echo Server (click the stopped row, or use the row menu → Start). HarborClient starts the Live Server, launches Express via the run command, opens a Live Page, and sets echo_server_base to the Live Server origin.

HarborClient Live Servers sidebar context menu with Start Edit Open folder Logs Copy ID and Delete actions
Right-click a Live Server for Start, Edit, Logs, and related management actions.

Open GET Echo and click Send. The response body should echo method GET, path /get, headers, and an empty or object body.

Open POST Echo and send it. Confirm the JSON body you configured appears under body in the echo response.

HarborClient Live Page showing JSON echo response from GET against the local Express server at 127.0.0.1:5500
Send through the proxy and inspect the Express echo JSON in the response or Live Page.

Repeat for PUT Echo and DELETE Echo.

From the Echo collection row menu, choose Run to open the collection runner and execute every request in the collection.

If a request fails, check the Live Server row menu → Logs for proxied access lines, and confirm Express is still running under the Live Server run command. Stop and start the Live Server after editing Run command or Proxy rules so the new config applies.

What you built

You now have a local Express echo API that HarborClient starts for you, a catch-all reverse proxy from the Live Server origin to port 3000, a global echo_server_base for request URLs, and an Echo collection you can send one request at a time or run as a batch.

Learn more in the docs for Live Servers, Requests, and Collections. Grab the latest HarborClient from harborclient.com or GitHub Releases.

Leave a Reply

Trending

Discover more from HarborClient Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading