▲ H--4 ▲

Hello World

Let's get your local server saying the magic words.

Before we begin.

You must have the dart SDK installed on your computer.

Installing dart

Install Dart on Linux, MacOS or Windows


Run the following command in your terminal to test that you have installed dart properly.

dart --version
 
> Dart SDK version: 3.4.4 (stable) (None) on "linux_x64"

Set up H4.

Run the command below to get started.

activate
dart pub global activate h4

Now, let's bootstrap your first app.

init
dart pub global run h4:init

After answering the prompts, the directory containing your app will have a file structure like this..

index.dart
.gitignore
analysis_options.yaml
CHANGELOG.md
pubspec.lock
pubspec.yaml
README.MD

Navigate to index.dart. Some code is already there.

index.dart
import 'package:h4/create.dart';
 
void main() async {
  var app = createApp(port: 5174);
  var router = createRouter();
  app.use(router);

  router.get("/", (event) => 'Hello world!')
}

You're all set! Let's run our server in dev mode.

dart pub global run h4:start --dev

Visit - http://localhost:5173 with your browser and voila! Hello world!

Let's now build a basic app with H4.

On this page