{"id":21275224,"url":"https://github.com/stirfry-js/stirfry","last_synced_at":"2025-07-11T07:30:42.496Z","repository":{"id":57371029,"uuid":"59040503","full_name":"StirFry-js/stirfry","owner":"StirFry-js","description":"StirFry is a self contained and lightweight web framework for nodejs","archived":false,"fork":false,"pushed_at":"2019-02-04T14:00:39.000Z","size":4442,"stargazers_count":24,"open_issues_count":6,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T01:24:59.421Z","etag":null,"topics":["help-wanted","http","http-server","node","nodejs","server","stirfry","up-for-grabs","web-framework","web-server","webserver"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StirFry-js.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":"2016-05-17T16:38:26.000Z","updated_at":"2020-10-05T15:10:54.000Z","dependencies_parsed_at":"2022-09-09T01:13:41.654Z","dependency_job_id":null,"html_url":"https://github.com/StirFry-js/stirfry","commit_stats":null,"previous_names":["squishybanana04/stirfry"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StirFry-js%2Fstirfry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StirFry-js%2Fstirfry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StirFry-js%2Fstirfry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StirFry-js%2Fstirfry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StirFry-js","download_url":"https://codeload.github.com/StirFry-js/stirfry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225704163,"owners_count":17511031,"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":["help-wanted","http","http-server","node","nodejs","server","stirfry","up-for-grabs","web-framework","web-server","webserver"],"created_at":"2024-11-21T09:28:34.406Z","updated_at":"2024-11-21T09:28:34.933Z","avatar_url":"https://github.com/StirFry-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![StirFry Logo](https://i.imgur.com/wclPQ7w.png)](https://github.com/StirFry-js/stirfry)\n\n___Fast___, ___lightweight___, ___self contained___, and ___easy to use___ web framework for [nodejs](http://nodejs.org).\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n\n## Table Of Contents ##\n * [What is this?](#whatisthis)\n * [Quick Start](#quickstart)\n * [About](#about)\n\n\u003ca name=\"whatisthis\"\u003e\u003c/a\u003e\n## What is this? ##\nStir Fry is a framework for making web servers in nodejs. It enables you to quickly and easily create web apps and servers. So, here is how to create one:\n\nThe first step is to create a server program that uses Stir Fry. Start by creating a folder, you can call it anything you want.\n\nMake sure you have Node.js installed on your computer. https://nodejs.org/en/download/\n\nNext navigate to that folder in terminal and run this command:\u003cbr\u003e\n`npm install stirfry`\u003cbr\u003e\nThat installs Stir Fry into the folder your server is running from. Next create a file called `server.js` and open it with your favourite code editor. Add this code: \u003cbr\u003e\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.request(function (request, response) {\n    response.send(\"Hello World!\");\n});\n```\nTo run `server.js`, type:\n`node server.js`\u003cbr\u003e\nmake sure you are in the same directory that has the `server.js` file in the terminal\u003cbr\u003e\nIf that doesn't work, try:\n`nodejs server.js`\u003cbr\u003e\nIf that doesn't work, you must install nodejs.\u003cbr\u003e\nAssuming you've done it right, you can go to `localhost:8080` in any web browser and it should show `Hello World!`\n#### How did that work?\nSetting the server to equal a `new StirFry(8080)` meant that you were telling the server to listen for any request on port 8080. Then calling `server.request` added the input as a response for requests.\n\nAfter all of the listeners have been called it sends the response to the user. You can add to the response by writing\n```javascript\nresponse.send(\"The thing you want to add to the response\");\n```\nSo by typing `response.send(\"Hello World!\")` you made that the response.\n#### Preprocessing the request and response objects ####\nStir Fry gives you the ability to preprocess the request and response objects. Basically that means you can write exensions and mods for stirfry. Here is an example\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.pre(function(request, response) {\n\t//Now I can change the request and response object before the next code runs\n    request.doubleURL = request.url + request.url;\n}\nserver.request(function(request, response) {\n\t//Now I can access request.doubleURL, and I also can in every request listener\n    respose.send(request.doubleURL);\n});\n```\n#### Extensions ###\nYou can create extensions using basically the same syntax as a normal server and use them just  by saying `server.use(extension)`, here is an example\nKeep in mind, extensions do not support adding layers. If you wish to create layers in your extension create a function that takes the server as an input and call it.\n```javascript\n\"use strict\";\nlet StirFry   = require('stirfry');\nlet extension = new StirFry.extension();\n//I can put more preprocessors and responders if I want\nextension.pre(function(request, response) {\n\trequest.doubleURL = request.url + request.url;\n});\nlet server = new StirFry(8080);\nserver.use(extension);\nserver.request(function(request, response) {\n\t//I can use request.doubleURL\n    response.send(request.doubleURL);\n});\n```\n\u003ca name=\"quickstart\"\u003e\u003c/a\u003e\n## Quick Start ##\n#### Creating your first server ####\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.request(function (request, response) {\n    response.send(\"Hello World!\");\n});\n```\nThis example creates a server on port 8080 and sets it to respond with `Hello World!` on any request. When you use `response.send` it appends the input to the response.\n#### Static File Servers ##\nStir Fry has a static file server method built in. All you need to do is this:\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.request(StirFry.static('public'));\n```\nPublic is the folder that the files get served from.\n\n#### Asynchronous Operations ##\nStir Fry lets you run multiple asynchronous operations at once. You can do all the preprocessing you want in the `server.process` layer, and then once all of those are done, it runs `server.pre` listeners, and once those are done it runs `server.request` listeners.\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\n\nlet fs = require('fs');\n\nserver.pre(function (request, response, end, async) {\n    async.start();\n    fs.readFile('file.txt', function (err, data) {\n        response.data = data.toString();\n        async.done();\n    });\n\n});\nserver.request(function (request, response) {\n    response.send(response.data);\n});\n```\nThis program uses `fs.readFile` to add a property to the response object and then sends it to the user. There are loads of more efficient ways to do this, this is just an example of how to use async.\n\n#### Sending Files ##\nStir Fry has a built in `response.sendFile` method, here is an example:\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.request(function (request, response) {\n    response.sendFile('file.html');\n});\n```\n#### Responding Only to Certain Requests ##\nWhen you create a request, preprocessor, or processor listener, you have the option of limiting it to certain requests by regex matching. Here is an example:\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server  = new StirFry(8080);\nserver.request(/\\/.*?\\/hi/, function (request, response) {\n    response.send(\"hi\");\n});\n```\nYou can access regex capture groups by accessing `request.params` as an array. `request.params` also processes query strings in the request.\n\n#### Installing plugins ####\nJust write `server.use(thePluginObject)`\n\n#### Creating Plugins ####\nCreating plugins works in a very similar way as creating servers. The only difference is you use `new StirFry.extension()` instead of `new StirFry()`. Then you can say `server.use(extension)` and it manages all of the listeners. Here is an example\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet extension = new StirFry.extension();\nextension.req(function(request, response) {\n\tlet log = `Request recieved with ${request.post ? `${request.post} as post and `:``} ${request.fullUrl || request.url} as the url. Recieved from ${request.ip} on `+ formatDate(new Date()); //Format date is defined externally\n\tconsole.log(log);\n});\n```\nThat is similar to the built in logger extension. Here is how you can use it\n```javascript\n\"use strict\";\nlet server = new StirFry(8080);\nserver.use(extension);\n```\nThe built in logger is a function that returns an extension because people are able to define a log file\n```javascript\n\"use strict\";\nlet StirFry = require('stirfry');\nlet server = new StirFry(8080);\nserver.use(StirFry.logger(\"logFile\"));\n```\n\n#### Post Requests ####\nYou can access post data by accessing `request.post` as an associative array\n\n#### Creating Layers ####\nAs of 1.6.0 StirFry allows the creation of custom layers in the server. The syntax for this involves the three functions `server.createLayer`, `server.destroyLayer`, and `server.placeLayer`.\nCreate layer takes a string that is the name of the layer to create.\nDestroy layer is the same as create layer but it will remove the it instead of creating it.\nPlace layer will take the names of two layers it will make it so that the layer that has the same name as the first input, always gets called after the layer that has the name of the second input.\n```javascript\n\"use strict\";\nlet StirFry = require('../../stirfry.js');\nlet server = new StirFry(8080, '0.0.0.0');\nserver.createLayer('final');\nserver.placeLayer('final', 'request');\nserver.addListenerOnLayer('final', function(req, res) {\n    res.send('Hello World!');\n});\n```\n\n## People\n\nThe original author of Stir Fry is [Alex Waese-Perlman](http://www.squishy-banana.com)\n\n[List of all contributors](https://github.com/StirFry-js/stirfry/graphs/contributors)\n\n## License\n\n  [MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/stirfry.svg\n[npm-url]: https://npmjs.org/package/stirfry\n[downloads-image]: https://img.shields.io/npm/dm/stirfry.svg\n[downloads-url]: https://npmjs.org/package/stirfry\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstirfry-js%2Fstirfry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstirfry-js%2Fstirfry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstirfry-js%2Fstirfry/lists"}