Ecosystem ↗

2. Run your first route

Create an application manually, run one JSON endpoint and inspect the actual result.

↗ View Markdown
LESSON 2 OF 820 min + practice · Beginner
  • Create a project manually
  • Return JSON from a file route
  • Check the running server without guessing

Your goal#

Run a small application and verify a real response. Use a terminal—a window for running commands—and an editor to change the listed files. Commands here run in your new application directory, not in the ZeruxJS monorepo root.

Check the prerequisite#

Use a Node version supported by the installed packages; Node 24 is a practical example for this walkthrough. Verify what is installed:

sh
node --version
npm --version

If either command is missing, install Node/npm using the official instructions for your operating system before continuing. No browser code or package can install the Node server runtime for you.

Create a directory and install dependencies#

sh
mkdir hello-zerux
cd hello-zerux
npm init -y
npm pkg set type=module
npm install zeruxjs@0.0.4 @zeruxjs/typescript@0.0.4
npm pkg set scripts.dev="zerux dev" scripts.build="zerux build" scripts.start="zerux start"

Implemented creators offer supported templates; this course creates files manually so each boundary is visible. The npm commands edit your application's package.json. The lockfile records dependency resolutions. Commit source/lockfiles to your project, but never private environment values.

Create the route file#

In your editor, create directories app, app/api, app/api/hello, then this file:

app/api/hello/route.ts
/** Return a public greeting. @returns JSON payload. Reads no globals, request data or services. */
export function GET() {
  return { message: 'Hello, ZeruxJS', ready: true };
}

A named GET export answers GET requests at this discovered route. Do not put the file in public: public files are served as assets, not discovered as handler modules.

Start and inspect#

sh
npm run dev

Keep this terminal running. Open the server address printed by the CLI, adding /api/hello. If the printed address is http://localhost:3000, use the following in a second terminal (PowerShell users may prefer curl.exe):

sh
curl http://localhost:3000/api/hello
Expected JSON fields
{"message":"Hello, ZeruxJS","ready":true}

Formatting/whitespace can differ; the JSON fields are the contract. The server must actually be running. Do not guess the port if the CLI prints another one.

Make a controlled change#

Change the greeting string, save, and request the same route again. Verify the response changed. If not, check the server terminal, actual file path, filename casing and whether you edited the project that is running.

A deliberate failure teaches you more#

Open a nonexistent address such as /api/not-a-route. Expect a missing-route response, not your greeting. Restore the valid URL. Learning to distinguish “server not running,” “route not found” and “handler threw” makes debugging much faster.

Try it yourself#

Add app/api/status/route.ts with a GET function returning { status: 'learning' }. Inspect both routes independently. Explain why changing /api/status should not change /api/hello.

You are done when: the valid endpoint returns the expected JSON, your change is visible and a nonexistent endpoint does not pretend to succeed.

Find the next detail#

See file conventions, routing and the full notes tutorial. If npm reports a missing script, use the solution finder rather than reinstalling arbitrary packages.

PUT IT INTO PRACTICE

Check your understanding

Try the exercise above, then answer both questions. Each correct answer earns 10 local learning points, once. You can retry; all lessons stay open.

Which file declares GET /api/hello in this course?

Explain the answer

app/api/hello/route.ts. The app directory holds discovered routes; route.ts exports HTTP method handlers.

What is useful evidence that the route works?

Explain the answer

The browser/HTTP client returns the expected JSON from the printed server URL. Run the application and inspect its actual response. A code suggestion alone is not runtime evidence.

Implementation sources

Implementation files for the APIs described on this page.

ZeruxJS · Open source · MIT OR Apache-2.0

Make yourself at home.

Every shortcut has a visible control too. Reading and navigation work without JavaScript.

Ctrl / ⌘ K
Search all documentation
/
Search, outside editable fields
?
This help, outside editable fields
↑ / ↓
Move through search results
Esc
Close a dialog or version menu
Progress, privacy, offline reading and controls →

Reset this learning record?

This removes course answers, exercise confirmations, bookmarks and recent pages for this docs version in this browser. Export a copy first if you want to keep it.

Search documentation

Type at least two characters.