A simple project with a user crud, github api integration and media upload/download.
- Typescript
- Node.js
- Express
- Prisma
- SQLite
- Multer
- EsLint
- Clone the repository.
- Navigate to the project directory.
- Install the dependencies using the following command:
npm install
- Create a
.env
file in the root directory and configure the following environment variables:
PORT=8080
FRONTEND_URL="your_frontend_url" (cors)
DATABASE_URL="file:./dev.db"
- Run the migrations to create the database schema:
npx prisma migrate dev
- Start the server:
npm run build
npm start
or
npm run dev
- The server will be running at
http://localhost:8080
.
User
Create a new user.
{
"name": "Matheus Tostes",
"email": "devtostes@example.com",
"password": "matheus321",
"login": "matheus1996"
}
Response Status: 201 Created
Body:
{
"name": "Matheus Tostes",
"email": "devtostes@example.com",
"login": "matheus1996"
}
Get a specific user.
Response Status: 200 OK
Body:
{
"id": 15,
"email": "devtostes@example.com",
"name": "Matheus Tostes",
"password": "matheus321",
"login": "matheus1996",
"createdAt": "2023-06-05T05:36:47.017Z",
"updatedAt": "2023-06-05T05:36:47.017Z"
}
Get all users.
Response Status: 200 OK
Body:
[
{
"name": "nathalia",
"email": "nathalia@gmail.com"
},
{
"name": "Matheus Tostes",
"email": "devtostes@example.com",
}
]
Update a specific user.
{
"name": "Matheus Tostes",
"email": "devtostesNew@example.com",
"password": "matheus321",
"login": "matheus1996"
}
Response Status: 200 OK
Body:
{
"name": "Matheus Tostes",
"email": "devtostes@example.com",
"login": "matheus1996"
}
Delete a specific user.
Response Status: 200 OK
Body:
{
"message": "User deleted"
}
Github
Get github user.
Response Status: 200 OK
Body:
{
"login": "MatheusTostes",
"id": 64822140,
"node_id": "MDQ6VXNlcjY0ODIyMTQw",
"avatar_url": "https://avatars.githubusercontent.com/u/64822140?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/MatheusTostes",
"html_url": "https://github.com/MatheusTostes",
"followers_url": "https://api.github.com/users/MatheusTostes/followers",
"following_url": "https://api.github.com/users/MatheusTostes/following{/other_user}",
"gists_url": "https://api.github.com/users/MatheusTostes/gists{/gist_id}",
"starred_url": "https://api.github.com/users/MatheusTostes/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/MatheusTostes/subscriptions",
"organizations_url": "https://api.github.com/users/MatheusTostes/orgs",
"repos_url": "https://api.github.com/users/MatheusTostes/repos",
"events_url": "https://api.github.com/users/MatheusTostes/events{/privacy}",
"received_events_url": "https://api.github.com/users/MatheusTostes/received_events",
"type": "User",
"site_admin": false,
"name": "Tostes",
"company": null,
"blog": "https://www.linkedin.com/in/matheustostes/",
"location": "Vila Velha - ES, Brasil",
"email": null,
"hireable": true,
"bio": "Let's code!!",
"twitter_username": null,
"public_repos": 37,
"public_gists": 0,
"followers": 72,
"following": 82,
"created_at": "2020-05-05T03:07:58Z",
"updated_at": "2023-06-04T11:53:16Z"
}
Media
Upload a new media.
structured: Multipart Form
fieldname: "file"
"file": media,
Response Status: 200 OK
Body:
{
"media": {
"fieldname": "file",
"originalname": "foto.jpg",
"encoding": "7bit",
"mimetype": "image/jpeg",
"destination": "...path/express-prisma-sqlite/public",
"filename": "1685942056461_foto.jpg",
"path": "...path/express-prisma-sqlite/public/1685942056461_foto.jpg",
"size": 19844
}
}
Download a specific media.
Response Status: 200 OK
Body:
media