# The default hello world app

In the terminal window, go to your folder of choice or create a new one, for example **c:\vibeprojects**. Inside that folder, type the command

**dub init hello --type=vibe.d**

or

**dub init hello -t vibe.d**

And press **Enter** at every prompt that follows to accept the defaults.

```
c:\vibeprojects>dub init hello -t vibe.d
Package recipe format (sdl/json) [json]:
Name [hello]:
Description [A simple vibe.d server application.]:
Author name [Owner]:
License [proprietary]:
Copyright string [Copyright ┬⌐ 2023, Owner]:
Add dependency (leave empty to skip) []:
     Success created empty project in c:\vibeprojects\hello
             Package successfully created in hello
```

Go inside the newly created hello project folder and explore it.

```
c:\vibeprojects>cd hello
c:\vibeprojects\hello>dir
 Volume in drive C has no label.
 Volume Serial Number is 4E0A-BFEF
 Directory of c:\vibeprojects\hello
2023-01-04  01:30 PM    <DIR>          .
2023-01-04  01:30 PM    <DIR>          ..
2023-01-04  01:30 PM               131 .gitignore
2023-01-04  01:30 PM               215 dub.json
2023-01-04  01:30 PM    <DIR>          public
2023-01-04  01:30 PM    <DIR>          source
2023-01-04  01:30 PM    <DIR>          views
               2 File(s)            346 bytes
               5 Dir(s)  134,991,044,608 bytes free
```

You are now inside the root directory of the hello application. To compile and run this application in one step (you haven’t done anything yet!), type

**dub**

Since this is the first time you will be running this command, this will download all the dependencies, then compile, then link, and then run the application.

*c:\vibeprojects\hello>***dub**

There will be a lot of messages before you see this at the tail end:

```
     Linking hello
             Copying files for vibe-d:tls...
     Running hello.exe
[main(----) INF] Listening for requests on http://[::1]:8080/
[main(----) INF] Listening for requests on http://127.0.0.1:8080/
[main(----) INF] Please open http://127.0.0.1:8080/ in your browser.
```

The last three lines indicate that the application has successfully compiled and the server is now running.

Open your browser and point it to localhost, port 8080.

[http://127.0.0.1:8080](https://www.google.com/url?q=http://127.0.0.1:8080/\&sa=D\&source=editors\&ust=1676218018092712\&usg=AOvVaw0Md_Ifsolo71nWwXe2RnQN)&#x20;

or

[http://localhost:8080](https://www.google.com/url?q=http://localhost:8080/\&sa=D\&source=editors\&ust=1676218018093592\&usg=AOvVaw1YnTEfdHOzE3T2BB_4X1iT)

and you will see the ‘Hello, World!’ message in your browser.

<figure><img src="https://3936448450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjGPCKHCWMHsDLNzX2hV8%2Fuploads%2F6wUJnVgA0FpCS4jr9vJp%2Fimage118.png?alt=media&#x26;token=5e8e501e-5996-44cd-8713-a1b2e087826c" alt=""><figcaption></figcaption></figure>

To stop the running application, press **Ctrl-C** (Control-C) on the terminal window. Sometimes you have to do it twice.

```
[00000000(----) INF] Received signal 2. Shutting down.
[main(----) INF] Stopped to listen for HTTP requests on ::1:8080
[main(----) INF] Stopped to listen for HTTP requests on 127.0.0.1:8080
^C
c:\vibeprojects\hello>
```

The common command options for **dub** are

dub init         - create a new project

dub run        - build and run combined

dub                - same as dub run

dub build       - completely compile the whole project and its dependencies but don’t run

dub test        - runs the unit tests

Let us take a closer look at the default application.

Open VS Code and go to *File->Open folder…*&#x20;

<figure><img src="https://3936448450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjGPCKHCWMHsDLNzX2hV8%2Fuploads%2FYs5bTtyT0TFzqkdVGDB1%2Fimage124.png?alt=media&#x26;token=34fc3e77-5b07-495b-848d-839272c4683f" alt=""><figcaption></figcaption></figure>

Then open the new application folder **hello**.

<figure><img src="https://3936448450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjGPCKHCWMHsDLNzX2hV8%2Fuploads%2FZnfssoMGCLpXbpw7UJg0%2Fimage122.png?alt=media&#x26;token=e3487527-a8cc-425c-9d2e-08586120dd9a" alt=""><figcaption></figcaption></figure>

In the Explorer window of VS Code, open **source\app.d** and you will see the automatically generated code.

<figure><img src="https://3936448450-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FjGPCKHCWMHsDLNzX2hV8%2Fuploads%2FrTsHPlMLV6H1gMQBkxIQ%2Fimage.png?alt=media&#x26;token=319bd385-0e79-49eb-9983-51028442007d" alt=""><figcaption></figcaption></figure>

```d
import vibe.vibe;
void main()
{
  auto settings = new HTTPServerSettings;
  settings.port = 8080;
  settings.bindAddresses = ["::1", "127.0.0.1"];
  auto listener = listenHTTP(settings, &hello);
  scope (exit)
  {
    listener.stopListening();
  }
  logInfo("Please open http://127.0.0.1:8080/ in your browser.");
  runApplication();
}
void hello(HTTPServerRequest req, HTTPServerResponse res)
{
  res.writeBody("Hello, World!");
}
```

In the **main()** method of **source\app.d**:

* a new HTTPServerSettings object is created
* the HTTP port number is set to 8080 (which you can change)
* the IP the server listens to is set to localhost in both IPv6 (“::1”) and IPv4 (“127.0.0.1”) format
* the listenHTTP(settings, \&hello) call means ‘run the hello() function using these settings’
* the runApplication() call starts the ball rolling (starts the event loop)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://reyvaleza.gitbook.io/vibe.d-tutorial/the-default-hello-world-app.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
