# Hello World (Single File)
- Require xpresser.
- 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.
- Define index route in xpresser
$.on.boot
event - 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.
- Boot File: where xpresser is called.
- Routes File: where routes are defined.
- 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