# Hello World (Single File)

  1. Require xpresser.
  2. Boot xpresser with your configuration.
    • $ is exposed as a global variable on boot, meaning it can be used in every file required/loaded in your project.
  3. Define index route in xpresser $.on.boot event
  4. Boot xpresser.

Run nodemon app.js or ts-node-dev app.ts and you should see your server started in console.

==> xpresser v{Your xpresser version}
==> Starting {Your App Name}...
==> Server started and available on http://localhost:2000/
==> PORT:2000

# Using MVC Structure.

When creating a real world application, You need Structure.

Xpresser provides MVC (Model, View & Controller) support out of the box.

To get started we need 3 files to achieve same Hello World.

  1. Boot File: where xpresser is called.
  2. Routes File: where routes are defined.
  3. Controller File: where actions to request are handled.

# Setup MVC Structure

In our single file example, we registered routes before calling $.boot(), well in this case we don't need that since we have specified a routesFile in our config.

See Configuration for more info.

# Routing

Create Routes file: routes.(js|ts)

paths.routesFile if defined in config, will be required by xpresser when booting up and all routes defined in it will be registered.

Read more on routing: XpresserRouter.

Create Controller: AppController.(js|ts)

# Run

# Javascript
node app.js

# Typescript
ts-node app.ts

Visit http://localhost:2000 (opens new window) on your browser, you should see Hello World and /about should show About Page

# What Next?

  1. Start a project using xjs-cli
  2. Configuration
  3. $ (The Dollar Sign)
  4. Routing