{"id":28541834,"url":"https://github.com/agm-dev/noswbi","last_synced_at":"2025-07-05T16:31:56.586Z","repository":{"id":57312080,"uuid":"208872810","full_name":"agm-dev/noswbi","owner":"agm-dev","description":"Node server with batteries included!","archived":false,"fork":false,"pushed_at":"2019-11-04T07:49:52.000Z","size":256,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-09T20:09:57.247Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/agm-dev.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":"2019-09-16T18:42:57.000Z","updated_at":"2020-04-20T08:04:46.000Z","dependencies_parsed_at":"2022-09-16T02:30:59.288Z","dependency_job_id":null,"html_url":"https://github.com/agm-dev/noswbi","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/agm-dev/noswbi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agm-dev%2Fnoswbi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agm-dev%2Fnoswbi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agm-dev%2Fnoswbi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agm-dev%2Fnoswbi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/agm-dev","download_url":"https://codeload.github.com/agm-dev/noswbi/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/agm-dev%2Fnoswbi/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263771060,"owners_count":23508854,"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":[],"created_at":"2025-06-09T20:10:05.385Z","updated_at":"2025-07-05T16:31:56.581Z","avatar_url":"https://github.com/agm-dev.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# noswbi\n\n[![Build Status](https://travis-ci.org/agm-dev/noswbi.svg?branch=master)](https://travis-ci.org/agm-dev/noswbi)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1b29f2fe0b184df0a3be55f95bb45912)](https://www.codacy.com/manual/agm-dev/noswbi?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=agm-dev/noswbi\u0026amp;utm_campaign=Badge_Grade)\n[![Codacy](https://api.codacy.com/project/badge/coverage/1b29f2fe0b184df0a3be55f95bb45912)](https://www.codacy.com/app/codacy/node-codacy-coverage)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/agm-dev/noswbi)\n![GitHub All Releases](https://img.shields.io/github/downloads/agm-dev/noswbi/total)\n![GitHub](https://img.shields.io/github/license/agm-dev/noswbi)\n\nNoswbi is a NodeJS HTTP server with everything but routes configured.\n\n## Install\n\n```bash\nnpm install --save noswbi\n```\n\n## Features\n\nNoswbi includes the following configuration / features:\n\n- helmet\n- compression\n- overload protection (only on production environment)\n- body-parser for JSON and urlencoded (extended false)\n- cors (can be enabled with `createServer(router, { allowCors: true }))\n- forces `Content-Type: application/json` on response headers (can be disabled with `createServer(router, { forceJsonResponse: false })`)\n- attach router routes to `/` unless `routesPrefix` provided on config when creating the server\n- authentication protection for routes\n- social login with Google\n- 404 not found handler included\n- error handler included\n\n## Production\n\nDon't forget to set the `NODE_ENV` variable to `\"production\"`. It will improve the performance of the server and will remove the stack trace from error handler. It will also enable the overload protection.\n\n## Usage\n\nThe idea behind noswbi is to provide a configured server, so you can focus only on coding the routes and logic of your API.\n\nNoswbi exposes two methods: `createRouter` and `createServer`. You can use them to easily create a server.\n\n### Simple server\n\n```javascript\n// Import the two required noswbi methods to create the server:\nconst { createRouter, createServer } = require(\"noswbi\");\n\n// Create the router:\nconst router = createRouter();\n\n// Add your logic to the router:\nrouter.get(\"/status\", (req, res) =\u003e res.status(200).json({ status: \"OK\" }));\n\n// Create the server by providing the configured router:\nconst server = createServer(router);\n\n// Start\nserver.listen(3000);\n```\n\n### Server with social login and protected routes\n\n```javascript\nconst mongoose = require(\"mongoose\");\nconst { createRouter, createServer } = require(\"noswbi\");\n\nconst router = createRouter();\n\nrouter.get(\"/\", (req, res) =\u003e res.send(\"holi\"));\n\n/**\n * The requests to the routes attached to this router require\n * an Authorization header with value `JWT ${token}`\n */\nconst protectedRoutes = createRouter({ requireAuth: true });\n\nprotectedRoutes.get(\"/protected-by-default\", (req, res) =\u003e\n  res.json({\n    message: \"this should be protected by default\",\n    user: req.user\n  })\n);\n\nconst options = {\n  allowCors: true,\n  forceJsonResponse: true, // default value\n  domain: process.env.DOMAIN,\n  routesPrefix: \"/\", // default value\n  auth: {\n    jwtSecret: process.env.JWT_SECRET,\n    issuer: process.env.JWT_ISSUER,\n    audience: process.env.JWT_AUDIENCE,\n    google: { // you will need to create an configure a Google app for login\n      clientID: process.env.GOOGLE_CLIENT_ID,\n      clientSecret: process.env.GOOGLE_SECRET\n    },\n    /**\n     * If you provide an user model with a method findOrCreate\n     * noswbi will call it with the user info provided by Google\n     * after succesful login.\n     */\n    userModel: require(\"./path/to/your/user/model\") // optional\n  }\n};\n\nconst server = createServer([router, protectedRoutes], options);\n\nmongoose.connect(\n  \"mongodb://localhost:27017/test\",\n  {\n    useNewUrlParser: true,\n    useUnifiedTopology: true\n  },\n  err =\u003e {\n    if (err) {\n      console.error(err);\n      process.exit(1);\n    }\n    server.listen(3000, () =\u003e console.log(\"running on 3000\"));\n  }\n);\n```\n\n## Examples\n\nYou can check full examples [here](./examples).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagm-dev%2Fnoswbi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagm-dev%2Fnoswbi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagm-dev%2Fnoswbi/lists"}