How to write code at server side in nakama

I am new in nakama just started working on nakama. i have run nakama server using docker-compose but i did not know to to code at server for nakama.

@kmsudhir It’s great you’re able to start and run the server with local development. The next steps before you start to write code with the server framework is usually to integrate one of our client sdks with your project but I can walk you through the “hello world” with the server framework and then share some links to help you learn other parts of the server functions you can write and call for your game logic.

  1. To start with lets check the layout of your project. You’ll want to have a code structure that looks like:

    ├── docker-compose.yml
    └── main.lua
  2. Inside your Docker compose file you’ll want to update the path you’ll use within the server to read Lua modules to look like:

    --runtime.path /nakama/data

    NOTE: You should add that change to the “nakama” service entrypoint cmdflags.

  3. Your “main.lua” file will have a very simple bit of logic to show that the server has loaded and executed the script:

    local nk = require("nakama")
        print("Hello World")

If everything is set up correctly you’ll see “Hello World” printed to the console when you run the server. Hope that helps.

I have done this part and want next move and to create user from client site. how to write code for this functionality

@kmsudhir There’s resources on the documentation for how to do this:

You should also download and unpack the client SDK based on which game engine or programming language you’re going to use for your project. There’s introductory guides for each of the client SDKs also on the docs.

I have download nakama open source code from and now want to modify according to me.

Now please suggest where to write my own code with nakama open source code. because i am little bit confuse with new code that how it will run with nakama open source code.

For me I am using
MacOS and Nakama:2.7.0 and my game engine is Unity

There are two languages supported by Nakama for now
Lua & Go , if you don’t know any of them I suggest you to start with lua language (my opinion as it is easier )

Now I really dont understand what do you mean by "suggest where to write my own code " but I think you are confused where you add you Lua files. My files structure looks like this

├── docker-compose.yml
└── nakama / data / modules (I keep all my .lua files here)

Now you can add a file like this my_rpc_calls.lua

The file contains this

local nk = require("nakama")

local function getservertime(context, payload)
    local resp = {
        current_time = os.time()
    return nk.json_encode(resp)


Now from client side, Lets say you are using unity

Task<IApiRpc> searchTask = _client.RpcAsync(Session,"GetServerTime");
IApiRpc Result = await searchTask;
print("Payload = "+Result.Payload);

If you are taking this seriously you should read the documentation (at least skim through it and read more about the things you need)

check It is very useful to learn lua by example and unity engine and how they are integrated.

the forum is very useful skim through the questions and answers there is always something new to learn

local nk = require(“nakama”)

local function getservertime(context, payload)
local resp = {
current_time = os.time()
return nk.json_encode(resp)


i have written same code in nakama and start nakama server but in unity not getting response then

how to test above function at server side that function working or not.

Use this code in unity

I recommend that you download and start it. Then you can check the code how they handle authentication / adding friend / calling RPC and more … basically you will get what need to get to the point where things make sense to you.

I am getting error RPC function not found

{“error”:“RPC function not found”,“message”:“RPC function not found”,“code”:5}