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.
Go inside the newly created hello project folder and explore it.
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:
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.
or
and you will see the ‘Hello, World!’ message in your browser.
To stop the running application, press Ctrl-C (Control-C) on the terminal window. Sometimes you have to do it twice.
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…
Then open the new application folder hello.
In the Explorer window of VS Code, open source\app.d and you will see the automatically generated code.
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)
Last updated