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:
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.
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.
[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>
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!");
}