DEV Community

Cover image for Setting Up a Simple Go Fiber Project
luthfisauqi17
luthfisauqi17

Posted on

3 1

Setting Up a Simple Go Fiber Project


In this tutorial, we will go step by step to set up a basic web server using Go Fiber. By the end of this guide, you will have a running Go Fiber application that responds with "Hello, World!" when accessed.

Step 1: Install Go

Before we start, ensure that Go is installed on your system. You can verify this by running:

go version
Enter fullscreen mode Exit fullscreen mode

If you don’t have Go installed, download and install it from golang.org.

Step 2: Create a New Go Project

Navigate to your desired directory and create a new project folder:

mkdir go-fiber-app && cd go-fiber-app
Enter fullscreen mode Exit fullscreen mode

Initialize a Go module:

go mod init go-fiber-app
Enter fullscreen mode Exit fullscreen mode

This will create a go.mod file, which manages dependencies for your project.

Step 3: Install Fiber

Run the following command to install Fiber:

go get github.com/gofiber/fiber/v2
Enter fullscreen mode Exit fullscreen mode

This fetches the Fiber package and adds it to your go.mod file.

Step 4: Create a Simple Fiber Server

Create a new file named main.go and add the following code:

package main

import (
    "log"
    "github.com/gofiber/fiber/v2"
)

func main() {
    app := fiber.New()

    // Define a simple route
    app.Get("/", func(c *fiber.Ctx) error {
        return c.SendString("Hello, World!")
    })

    // Start the server
    log.Fatal(app.Listen(":3000"))
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Run the Fiber App

Now, let's run our Go Fiber application:

go run main.go
Enter fullscreen mode Exit fullscreen mode

Open your browser and visit http://localhost:3000. You should see:

Hello, World!
Enter fullscreen mode Exit fullscreen mode

There you go, that is how you setting up a simple golang Fiber project. Thank you for reading, and have a nice day!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

5 Playwright CLI Flags That Will Transform Your Testing Workflow

  • 0:56 --last-failed
  • 2:34 --only-changed
  • 4:27 --repeat-each
  • 5:15 --forbid-only
  • 5:51 --ui --headed --workers 1

Learn how these powerful command-line options can save you time, strengthen your test suite, and streamline your Playwright testing experience. Click on any timestamp above to jump directly to that section in the tutorial!

πŸ‘‹ Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay