{"id":19985897,"url":"https://github.com/aeberdinelli/node-api","last_synced_at":"2026-02-22T14:03:54.354Z","repository":{"id":42336465,"uuid":"198275967","full_name":"aeberdinelli/node-api","owner":"aeberdinelli","description":"A working NodeJS API with dynamic endpoints to quickly start your project.","archived":false,"fork":false,"pushed_at":"2022-12-10T23:18:29.000Z","size":206,"stargazers_count":4,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-21T02:18:09.132Z","etag":null,"topics":["api","expressjs","mongodb","node"],"latest_commit_sha":null,"homepage":"","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/aeberdinelli.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-07-22T17:58:02.000Z","updated_at":"2024-05-21T02:18:09.133Z","dependencies_parsed_at":"2022-09-15T01:53:55.355Z","dependency_job_id":null,"html_url":"https://github.com/aeberdinelli/node-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fnode-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fnode-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fnode-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fnode-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aeberdinelli","download_url":"https://codeload.github.com/aeberdinelli/node-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224388461,"owners_count":17303088,"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","expressjs","mongodb","node"],"created_at":"2024-11-13T04:26:44.739Z","updated_at":"2026-02-22T14:03:49.316Z","avatar_url":"https://github.com/aeberdinelli.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node-api\r\nQuickly start your project by just cloning this repo!\r\n\r\n## Install\r\nJust clone this repo, run `npm install` and you should have a complete node crud api. Of course, you need NodeJS and MongoDB installed first. Here's a detailed step by step:\r\n\r\n- [Install NodeJS](https://nodejs.org/es/) version \u003e= 10\r\n- [Install MongoDB](https://www.mongodb.com)\r\n- Clone this repo: `git clone https://github.com/aeberdinelli/node-api.git` (you can also fork this so you can just push to your own repo with this API as a base)\r\n- Install node dependencies: `npm install`\r\n- Set log outputs: \r\n    - On Mac/Linux: `export DEBUG=API*`\r\n    - On Windows: `set DEBUG=API*`\r\n- Run! `npm start`\r\n\r\n## Using\r\nThis api will read all the mongoose schemas inside `src/schemas` and create endpoints for each one of them. There's already a schema that you can use as an example which is also needed in order for this API to work.\r\n\r\nFor example, if you want to create a CRUD for books, you can create a schema file like this:\r\n\r\n```javascript\r\nconst mongoose = require('mongoose');\r\n\r\nlet SchemaBooks = new mongoose.Schema({\r\n\t'title': {\r\n\t\ttype: String\r\n\t},\r\n\t'author': {\r\n\t\ttype: String\r\n\t},\r\n\t'deleted': {\r\n\t\ttype: Boolean,\r\n\t\tdefault: null\r\n\t}\r\n});\r\n\r\nmodule.exports = mongoose.model('Book', SchemaBooks);\r\n```\r\n\r\n## Permissions\r\nThis API supports permissions per user per endpoint. For example, if you want to add a user that can create, delete and read books but can only read authors, you should add a document like this in the users collections in MongoDB:\r\n\r\n```javascript\r\n{\r\n    \"name\" : \"An user who have full access for the book endpoint but read only for author\",\r\n    \"lastname\" : \"Some\",\r\n    \"nickname\" : \"User\",\r\n    \"email\" : \"some@user\",\r\n    \"phone\" : \"+1 321 1234567\",\r\n    \"password\" : \"$2b$10$RqMmS35qslNgqFwebcwy4.g3gfVic51u3bAeAtytAPcpjHmQth/bm\",\r\n    \"privileges\" : [\r\n        {\r\n            \"model\" : \"book\",\r\n            \"methods\" : [ \r\n                \"GET\", \r\n                \"POST\", \r\n                \"PUT\", \r\n                \"DELETE\"\r\n            ]\r\n        }, \r\n        {\r\n            \"model\" : \"author\",\r\n            \"methods\" : [ \r\n                \"GET\"\r\n            ]\r\n        }\r\n    ],\r\n    \"deleted\" : null\r\n}\r\n```\r\n\r\n**Tip**: You can create a POST request to the `user` endpoint to create it and update the privileges later so the API will encrypt the password for you. (And for security reasons, the API will ignore the privileges property on the request).\r\n\r\n## Settings\r\nTo make this API easily configurable in different environments, most of the settings are used from environment variables. Here's a table with the available vars.\r\n\r\n\u003ctable\u003e\r\n\t\u003cthead\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003cth\u003eName\u003c/th\u003e\r\n\t\t\t\u003cth\u003eType\u003c/th\u003e\r\n\t\t\t\u003cth\u003eDefault value\u003c/th\u003e\r\n\t\t\t\u003cth\u003eDoc\u003c/th\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\u003c/thead\u003e\r\n\t\u003ctbody\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003ePORT\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003enumber\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003e3000\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003eDefines the port to use in the API\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003ePRETTY_PRINT\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eboolean\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003efalse\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e(Works only if you have views), sets if pretty prints the HTML when you use a template engine\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eMONGODB_URL\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003estring\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003emongodb://localhost:27017/\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003eThe URL for the MongoDB connection\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eMONGODB\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003estring\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cem\u003enull\u003c/em\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cstrong\u003erequired\u003c/strong\u003e\r\n\t\t\t\tName of the database to use\r\n\t\t\t\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eDEBUG\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003estring\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cem\u003enull\u003c/em\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003eThis sets the logs output to the console. I recommend you use this value: \u003ccode\u003eAPI*\u003c/code\u003e. That will enable all logs for the API and its sublevels\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eJWT_SIGNATURE\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003estring\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cem\u003enull\u003c/em\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cstrong\u003erequired\u003c/strong\u003e\r\n\t\t\t\tThe JWT signature. You can use any word just like \u003ccode\u003epepe\u003c/code\u003e. Also, you can change this to disable all the existing JWT tokens forcing a new login\r\n\t\t\t\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eJWT_LIFETIME\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003estring\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003e9\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\tThe JWT session token lifetime, in hours.\r\n\t\t\t\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\t\u003ctr\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003eGUEST_PRIVILEGES\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003earray\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\t\u003cpre\u003e['GET']\u003c/pre\u003e\r\n\t\t\t\u003c/td\u003e\r\n\t\t\t\u003ctd\u003e\r\n\t\t\t\tAn array with the allowed http verbs for a guest (for example, if you want all guest to be able to create and read things, you should set this to \u003ccode\u003e['POST','GET']\u003c/code\u003e)\r\n\t\t\t\u003c/td\u003e\r\n\t\t\u003c/tr\u003e\r\n\t\u003c/tbody\u003e\r\n\u003c/table\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fnode-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faeberdinelli%2Fnode-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fnode-api/lists"}