FuziData - NodeJS DataStore

About

Hey! I recently made my own NodeJS Datastore and I wanted to share it on the devforum! It’s very simple to use and fast to set up.

Setting it up

  1. Log into your glitch account at https://glitch.com/ (Register one if you don’t have one)
  2. Create a new hello-express project and call it whatever you want
  3. Start editing your project & make it private if you want to
  4. Replace your key icon.env file with this:
CODE=EXAMPLECODE

Don’t use any spaces.
Make sure the code is complicated so people can’t guess it!
5. Replace the server.js file with this script:

// DONT MODIFY ANYTHING UNLESS YOU KNOW WHAT YOU ARE DOING!!!
var express = require('express');
const store = require('data-store')
const mystore = new store({path: 'store.json'});
var app = express();
app.get("/", function (request, response) {
  response.send("Roblox NodeJS DataStore by TheFuzi!")
});
app.get("/get", function (request, response) {
  if (request.query.key === process.env.CODE) {
    response.send(mystore.get(request.query.userid))
  }else{
    response.send('wrong key bud')
  }
});
app.get("/save", function (request, response) {
  if (request.query.key === process.env.CODE) {
    mystore.set(request.query.userid,request.query.data)
    response.send('success!')
  }else{
    response.send('wrong key gamer')
  }
});
var listener = app.listen(process.env.PORT, function () {
  console.log('Your app is listening on port ' + listener.address().port);
});

  1. Replace the package.json file with this:
{
	"name": "FuziData",
	"version": "0.0.1",
	"description": "fuzi's new hot datastore system",
	"main": "server.js",
	"scripts": {
		"start": "node server.js"
	},
	"dependencies": {
    "express": "^4.12.4",
    "data-store": "^3.1.0"
	},
	"keywords": [
		"node",
		"express",
		"nedb"
	],
	"license": "MIT"
}

  1. Make a new file called store.json . We’ll use this for storing data.

We’re done with glitch, let’s move to roblox studio!

  1. First of all, grab this module:
    https://www.roblox.com/library/3404631297/FuziData-Roblox-External-DataStore
  2. Place the module in your game
  3. Enable Http Requests in your roblox game’s settings.

Look at the Usage tab for some use examples and the API tab to view the api.

API

module:GetAsync() - use this to get the data
arguments:

  1. Link to your project (ex. http://EXAMPLENAME.glitch.me/)
  2. Your secret key stored in the .env file
  3. save’s name (mostly player’s userid)

module:SetAsync() - use this to set the data
arguments:

  1. Link to your project (ex. http://EXAMPLENAME.glitch.me/)
  2. Your secret key stored in the .env file
  3. save’s name (mostly player’s userid)
  4. Data to save (table/number/bool/string)

Use Examples

Saving a number/string/bool
local FuziData = require(game.ServerScriptService.FuziData) -- FuziData module's directory
local web = "http://YOURPROJECTSNAME.glitch.me/"
local key = "" -- replace this with your secret key from the .env file
local http = game:GetService('HttpService')
game.Players.PlayerAdded:Connect(function(plr)
	local f = Instance.new('Folder',plr)
	f.Name = "leaderstats"
	local int1 = Instance.new('StringValue')
	int1.Value = FuziData:GetAsync(web,key,plr.UserId) or 0
	int1.Name = "value1"
	int1.Parent = f
end)
game.Players.PlayerRemoving:Connect(function(plr)
	FuziData:SetAsync(web,key,plr.UserId,plr.leaderstats.value1.Value)
end)
Saving a table
local FuziData = require(game.ServerScriptService.FuziData)
local web = "http://YOURPROJECTSNAME.glitch.me/"
local key = "" -- replace this with your secret key from the .env file
local http = game:GetService('HttpService')
game.Players.PlayerAdded:Connect(function(plr)
	local plr_data
	if FuziData:GetAsync(web,key,plr.UserId) == nil then
		plr_data = {
			value1 = 0,
			value2 = 0	
		}
	else
		plr_data = FuziData:GetAsync(web,key,plr.UserId)
	end
	local f = Instance.new('Folder',plr)
	f.Name = "leaderstats"
	local int1 = Instance.new('IntValue')
	int1.Value = plr_data.value1
	int1.Name = "value1"
	int1.Parent = f
	local int2 = Instance.new('IntValue')
	int2.Value = plr_data.value2
	int2.Name = "value2"
	int2.Parent = f
end)
game.Players.PlayerRemoving:Connect(function(plr)
	local plr_data = {
		value1 = plr.leaderstats.value1.Value,	
		value2 = plr.leaderstats.value2.Value,
	}
	FuziData:SetAsync(web,key,plr.UserId,plr_data)
end)

Hope you enjoy my tutorial! :smile:
Feedback would be appreciated!

4 Likes

This topic was automatically closed after 13 minutes. New replies are no longer allowed.