{"id":15489585,"url":"https://github.com/pablopunk/iga","last_synced_at":"2025-04-22T18:24:37.404Z","repository":{"id":34985820,"uuid":"194449158","full_name":"pablopunk/iga","owner":"pablopunk","description":"Zero config typescript/es6 server with the filesystem as the router","archived":false,"fork":false,"pushed_at":"2023-05-06T04:27:55.000Z","size":565,"stargazers_count":7,"open_issues_count":5,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T04:14:06.029Z","etag":null,"topics":["api","automatic","easy","es6","fast","nextjs","nodejs","quick","routes","server","typescript","zero-config"],"latest_commit_sha":null,"homepage":"https://pablopunk.com/iga","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pablopunk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-29T21:18:02.000Z","updated_at":"2024-08-03T17:58:11.000Z","dependencies_parsed_at":"2023-01-15T11:31:01.159Z","dependency_job_id":null,"html_url":"https://github.com/pablopunk/iga","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablopunk%2Figa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablopunk%2Figa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablopunk%2Figa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pablopunk%2Figa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pablopunk","download_url":"https://codeload.github.com/pablopunk/iga/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240441940,"owners_count":19801793,"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":["api","automatic","easy","es6","fast","nextjs","nodejs","quick","routes","server","typescript","zero-config"],"created_at":"2024-10-02T07:06:33.001Z","updated_at":"2025-03-04T04:30:36.266Z","avatar_url":"https://github.com/pablopunk.png","language":"JavaScript","readme":"# iga\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/pablopunk/iga\"\u003e\u003cimg src=\"https://img.shields.io/travis/pablopunk/iga.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/pablopunk/miny\"\u003e\u003cimg src=\"https://img.shields.io/badge/made_with-miny-1eced8.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/iga\"\u003e\u003cimg src=\"https://img.shields.io/npm/dt/iga.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://packagephobia.now.sh/result?p=iga\"\u003e\u003cimg src=\"https://packagephobia.now.sh/badge?p=iga\" alt=\"install size\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ci\u003eZero config typescript/es6 server with the filesystem as the router\u003c/i\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.githubusercontent.com/pablopunk/art/master/iga/iga.svg?sanitize=true\" alt=\"logo\"\u003e\n\u003c/p\u003e\n\nInspired by [NextJS](https://github.com/zeit/next.js), `iga` exposes a lightweight server using your file system as a router.\n\n- One command\n- 0 config ES6 modules\n- Typescript out of the box\n- Use the file system as the router\n- Automatic code reloading\n\n\u003chr/\u003e\n\n- [Install](#install)\n- [Usage](#usage)\n  - [Routes](#routes)\n  - [Response/Request](#response--request)\n  - [Helpers](#helpers)\n- [ES6/Typescript](#es6--typescript)\n  - [async/await](#asyncawait)\n- [CLI](#cli)\n  - [Commands](#commands)\n  - [Options](#options)\n- [Programmatic Usage](#programmatic-usage)\n  - [Options](#options-1)\n- [Deploy](#deploy)\n- [License](#license)\n- [Author](#author)\n\n\u003chr/\u003e\n\n## Install\n\n```sh\nnpm install iga\n```\n\n## Usage\n\nIn your `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"dev\": \"iga\",\n    \"start\": \"iga start\"\n  }\n}\n```\n\nThen create a `routes` folder with an `index.js`. Each route should export a function with the **standard NodeJS `request` and `response` objects** with some [helpers](#helpers).\n\n```js\n// routes/index.js\nexport default () =\u003e 'Hello from iga!'\n```\n\nIf you run `npm start` and you visit http://localhost:3000 you will see `Hello from iga!`.\n\n### Routes\n\nNow let's create another endpoint. Create a file `routes/random-fruit.js`:\n\n```js\n// routes/random-fruit.js\nexport default () =\u003e {\n  const fruits = ['apple', 'orange', 'pear']\n  const random = Math.floor(Math.random() * 3)\n\n  return fruits[random]\n}\n```\n\nNow if you run `npm start` again and visit http://localhost:3000/random-fruit you will get any of the fruits we declared in the file.\n\nIf you don't want to restart the server everytime you make changes, use `npm run dev` to disable cache and see the latest changes to your code.\n\n#### Response / Request\n\n`iga` catches the return value of your function and makes an http response with it, so you can do things like:\n\n- `return 'some text'`: Response will be plain text\n- `return { foo: bar }`: Response will be JSON\n- `return 403`: Response will send a 403 status code\n\nIf you still want to do something manually, you can use both `request` and `response` objects, like:\n\n```js\nexport default (req, res) =\u003e {\n  res.end(`Hello from ${req.url}`)\n}\n```\n\nIn this case the return value will be ignored, because http headers have already been sent with `res.end`.\n\n#### Helpers\n\n\u003e `request.query`\n\nContains the result of `require('url').parse(req.url, true).query`, so you can code faster:\n\n```js\n// routes/find-user.js\nexport default req =\u003e {\n  if (!req.query.userId) {\n    return 403 // bad request\n  }\n\n  const user = getUserFromDatabase({ id: req.query.userId })\n  if (!user) {\n    return 404 // not found\n  }\n\n  return { results: [user] }\n}\n```\n\n#### Filesystem as the router\n\nAs you might have noticed by the previous examples, `iga` convers your file system into routes as follows:\n\n- `routes/index.js`: `/`\n- `routes/foo.js`: `/foo`\n- `routes/foo/bar.js`: `/foo/bar`\n- `routes/also-typescript.ts`: `/also-typescript`\n\n## ES6 / Typescript\n\nBy default, `iga` allows you to write your code in es5 `module.exports`, es6 `export default`or even **typescript**, with 0 configurations, thanks to [sucrase](https://sucrase.io). For `.js` files it will allow you to write es6 modules, but you can also directly write typescript in `.ts` files.\n\n```ts\nimport { ServerResponse, IncomingMessage } from 'http'\n\nexport default function(req: IncomingMessage, res: ServerResponse) {\n  res.end('hello from typescript.ts')\n}\n```\n\n### async/await\n\nIf you want to, your exported function can be an `async` function so you can use `await` inside it to manage promises.\n\n## CLI\n\n### Commands\n\n\u003e `iga`\n\nWithout any arguments, `iga` will build your project everytime there's a change in your `routes` folder, so you can focus on coding.\n\n\u003e `iga start`\n\nIt will start the server without rebuilding. This should be used in production.\n\n### Options\n\n\u003e `-p | --port XXXX`\n\n_Optional_. Start the server on port `XXXX`. Defaults to 3000.\n\n####\n\n## Programmatic usage\n\n`iga` exposes an API so it's easier to test and use as a library:\n\n```js\nimport iga from 'iga'\nimport http from 'http'\n\nconst server = new http.Server(iga)\n```\n\nIf you want, there are some options you can customize:\n\n```js\nimport { getMiddleWare } from 'iga'\nimport http from 'http'\n\nconst server = new http.Server(\n  getMiddleWare({\n    routes: __dirname,\n    useCache: false\n  })\n)\n```\n\n### Options\n\n#### `routes?: string`\n\n\u003e Path to the folder that contains your routes\n\nDefault: `path.join(process.cwd(), 'routes')`\n\n#### `useCache?: boolean`\n\n\u003e If `false` everytime you change your code you will\n\u003e be able to see the new version on the server\n\u003e This is what `iga` command uses with no arguments\n\nDefault: `true`\n\n## Deploy\n\nAny provider that can run NodeJS will work. If you want to use [now.sh](https://now.sh), I made a [simple example](https://github.com/pablopunk/iga-example) that works. It uses `deploy.js` as the lambda in now.sh.\n\n## License\n\nMIT\n\n## Author\n\n| ![me](https://gravatar.com/avatar/fa50aeff0ddd6e63273a068b04353d9d?size=100) |\n| ---------------------------------------------------------------------------- |\n| [Pablo Varela](https://pablo.pink)                                           |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablopunk%2Figa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpablopunk%2Figa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpablopunk%2Figa/lists"}