{"id":13614537,"url":"https://github.com/ScarletsFiction/Serberries","last_synced_at":"2025-04-13T18:33:13.569Z","repository":{"id":57362592,"uuid":"143511228","full_name":"ScarletsFiction/Serberries","owner":"ScarletsFiction","description":"Serberries is a Nodejs live webserver that able to live refresh your script on the realtime","archived":false,"fork":false,"pushed_at":"2020-01-05T12:56:59.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-25T00:01:12.627Z","etag":null,"topics":["livereload","nodejs","realtime","server"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ScarletsFiction.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-04T08:22:11.000Z","updated_at":"2020-01-05T12:57:01.000Z","dependencies_parsed_at":"2022-09-26T16:32:13.431Z","dependency_job_id":null,"html_url":"https://github.com/ScarletsFiction/Serberries","commit_stats":null,"previous_names":["scarletsfiction/skylibrary"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FSerberries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FSerberries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FSerberries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScarletsFiction%2FSerberries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScarletsFiction","download_url":"https://codeload.github.com/ScarletsFiction/Serberries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248322601,"owners_count":21084337,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["livereload","nodejs","realtime","server"],"created_at":"2024-08-01T20:01:02.839Z","updated_at":"2025-04-13T18:33:13.245Z","avatar_url":"https://github.com/ScarletsFiction.png","language":"JavaScript","funding_links":["https://www.patreon.com/stefansarya"],"categories":["JavaScript"],"sub_categories":[],"readme":"\u003ca href=\"https://www.patreon.com/stefansarya\"\u003e\u003cimg src=\"http://anisics.stream/assets/img/support-badge.png\" height=\"20\"\u003e\u003c/a\u003e\n\n[![Written by](https://img.shields.io/badge/Written%20by-ScarletsFiction-%231e87ff.svg)](LICENSE)\n[![Software License](https://img.shields.io/badge/License-MIT-brightgreen.svg)](LICENSE)\n[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Serberries%20is%20a%20fast%20Nodejs%20live%20webserver%20that%20able%20to%20live%20refresh%20your%20script%20on%20the%20realtime.\u0026url=https://github.com/ScarletsFiction/Serberries\u0026via=github\u0026hashtags=serberries,live,refresh,server,node)\n\n# Serberries\nSerberries is a fast Nodejs live webserver that able to live refresh your script on the realtime.\n\nThis library was useful if you always updating your server script but tired of restarting your server every changes.\n\n## Install\nTo install this library, you can download from this repository or use\n\u003e $ npm install serberries\n\n## Sample Usage\n\n```js\nvar Serberries = require('serberries');\n\nvar myserver = new Serberries({\n    // path:__dirname+'/router', // (Deprecated)\n    router:'router', // Directory path if you want to route http request\n    modules:'modules', // Directory path for non router\n    // All folder above have live reload on any script changes\n    \n    maxRequestSize:1e6, // Maximum size when receiving POST data\n    allowedOrigins:['www.example.com'], // Allow CORS request\n    public:\"../public\", // Set public folder for serving static assets\n});\n\n// Set public folder for serving static assets (Deprecated)\n// myserver.setPublicFolder(\"../public\");\n\n// Set variable to be accessed from the router scopes\nmyserver.scopes.myWorld = \"my world\";\n\n// Obtaining reference of http.createServer() to be used in Socket.io or other\n// var app = myserver.server;\n\n// Starting the server\nmyserver.start(8000);\n```\n\n### Listen to events\n```js\nmyserver.on('error', function(errcode, msg, trace){\n    console.error(\"Error code: \"+errcode+' ('+msg+')');\n    if(trace){\n        console.error(trace.message);\n        for (var i = 0; i \u003c trace.stack.length; i++) {\n            console.error(\"   at \"+trace.stack[i]);\n        }\n    }\n    console.error(\"\");\n});\n\nmyserver.on('loading', function(filename){\n    console.log('Loading '+filename);\n});\n\nmyserver.on('loaded', function(urlpath, type){\n    console.log('URL to '+urlpath+' was '+type);\n});\n\nmyserver.on('stop', function(){\n    console.log(\"Server shutdown\");\n});\n\nmyserver.on('started', function(){\n    console.log(\"Server was started\");\n});\n\nmyserver.on('removed', function(urlpath){\n    console.log('URL to '+urlpath+' was removed');\n});\n\nmyserver.on('httpstatus', function(code, callback){\n    callback('Returning HTTP status '+code);\n});\n\nmyserver.on('navigation', function(data){\n    console.log(\"Navigation to '\"+data.path+\"'\");\n    console.log('  - '+data.headers['user-agent']);\n});\n```\n\n### Using router for handling request\n\n```js\n// hello.js\n\n// This will be initialized as an object on initialize\n// you can keep your variable here and load it even\n// the script reloaded\nvar scope = null;\nvar myWorld = '';\n\n// Any variable declared not in `scope` variable\n// will be reset to initial state\n// so you can also live reload your other script\nvar dependency = require('./ext/hello.js');\n\nfunction response(req, res, closeConnection){\n    res.writeHead(200);\n\n    // This will remain in `scope` variable even this script was reloaded\n    // So if you have `setInterval`, you better save it on the scope\n    scope.mySaveData = \"I have some data that was saved\";\n\n    var output = dependency.hello() + \" \" + (req.get.who ? req.get.who : myWorld) + '!';\n\n    //res.write(output);\n    closeConnection(output);\n}\n\n// Minimal structure for router\nmodule.exports = {\n    // URL path\n    path: '/hello', // URL path must be started with backslash\n    // If you doesn't provide the backslash, it can't be accessed with URL\n    // To use this router for all subpath '/hello#'\n\n    // Response handler\n    response:response,\n\n    // Scope initialization after script loaded\n    // scope:function(){}, [Deprecated]\n    init:function(ref, scopes){\n        scope = ref;\n        myWorld = scopes.myWorld;\n\n        if(ref.mySaveData)\n            console.log(ref.mySaveData);\n\n        // You can also access other scope with 'scopes'\n        // \n        // this script filename is 'hello.js' so this\n        // scope can be accessed from scopes['hello']\n        // \n        // ref === scopes['hello']\n        // scopes.myWorld === \"my world\"\n    },\n\n    // Optional if you want to destroy some data when script was reloaded\n    destroy:function(){\n\n    }\n}\n```\n\n### Define modules for the server\nActually you're free to build your module structure, but make sure that you saving your variables on the scope if you want to reuse it. Any variable that not referenced in another object will be removed when garbage collection process. Variable that referenced inside of setInterval or Event is not removed if it's still running.\n\n```js\n// library-1.js\nvar scope = null;\nmodule.exports = {\n    // Optional if you want to access other scope\n    // or saving data for current scope\n    init:function(ref, allRef){\n        // Running once this script was loaded\n        scope = ref;\n    },\n\n    // Optional if you want to destroy some data when script was reloaded\n    destroy:function(){\n\n    }\n}\n```\n\n## Contribution\n\nIf you want to help in Serberries, please fork this project and edit on your repository, then make a pull request to here.\n\nKeep the code simple and clear.\n\n## License\n\nSerberries is under the MIT license.\n\nBut don't forget to put the a link to this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScarletsFiction%2FSerberries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FScarletsFiction%2FSerberries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FScarletsFiction%2FSerberries/lists"}