- About the Project
- Requirements
- Tech Stack and Packages used
- Initial Setup
- Working with docker
- Running Project locally
- API of application
- Support
Just a simple but effective backend for a todo application.
- Node.js and npm installed for your OS.
- You need to have docker installed for your OS.
- GraphQL-Playground for testing your API.
- Docker used to contain dependencies and tooling
node
>= 8.9.0npm
>= 5.5.1TypeScript
>= 3.0.1graphql
for making API queriesmongoDb
for databasewinston
for logging/monitoring applicationgulp
for solving problem of repetitionbluebird
for promisesmocha and chai
for testingnyc
for code coveragets-node
for traspiling TypeScript on the server so that it could be used in Node.jstslint
for linting code
// Cloning the repository
git clone https://github.com/knrt10/Todo-backendAPI.git
// Change directory to project folder
cd Todo-backendAPI/
After following above intital steps, its very easy to access the api using docker. All you need is to do it follow small steps given below.
Initial mongoDb is setup for localhost. master
branch contains setup for running server using npm
so you need to change branch
git checkout docker
After changing that run this command
npm run dockerStart
This will run a script scripts/dockerCompose.sh
and create docker image and with help of docker-compose.yml
from our project directory it will start server automatically. Now to access the application proceed to API of application.
To Stop Our Docker process type this command in your terminal
npm run dockerStop
Follow these simple steps
- Installing dependencies
npm i
- This will create a
node_modules
folder.
- Building the project
- After dependencies are installed run
npm run build
- This will build the application and create a
dist/
folder
- After dependencies are installed run
- Starting mongodb Server
- You need to start your mongodb server for your OS. For Mac and Unix it is
mongod
.
- You need to start your mongodb server for your OS. For Mac and Unix it is
- Running the application
- Start your application by running
npm start
ornpm run dev
- Start your application by running
- Accessing API of application
- Now to access the application proceed to API of application.
- Stopping the application
- press ctrl + c in your terminal where server is runnning.
- Running docker again.
- If you want to run docker again follow Working with docker.
IMPORTANT:- To run tests your config should be localDatabase: true
in shared/config.ts
and your local mongoDB server should be running. If so then run simple command
npm run build && npm run coverage
You can lint the code automatically by running this is your terminal
npm run lint
This is simple API of application. Go to http://localhost:3000/graphql
or open GraphQL-Playground and enter above URL for testing your API.
mutation registerUser($input: UserInputRegister) {
registerUser(input: $input) {
code
message
data {
token
success
user {
id
createdAt
username
name
password
updatedAt
}
}
}
}
and input
{
"input": {
"username": "knrt10",
"name": "Kautilya",
"password": "test"
}
}
query loginUser($input: UserInputLogin) {
loginUser(input: $input) {
code,
message,
data {
success
user {
id
name
username
password
}
token
}
}
}
and input
{
"input": {
"username": "knrt10",
"password": "test"
}
}
query profileUser{
profileUser {
code
message
data {
success
token
user {
name
}
}
}
}
and headers
{
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}
mutation addTodo($input: todoInput) {
addTodo(input: $input) {
code
message
data {
success
todo {
id
postedByid
description
updatedAt
createdAt
name
}
}
}
}
and input
{
"input": {
"title": "knrt10",
"description": "test"
}
}
and also headers
{
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}
query todoUsers {
todoUsers{
code
message
data {
success
todos {
title
description
}
}
}
}
and also headers
{
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}
mutation updateTodo($input: todoInputUpdate) {
updateTodo(input: $input) {
code
message
data {
success
todo {
id
postedByid
description
updatedAt
createdAt
name
title
}
}
}
}
and input
{
"input": {
"id": "5c2503576c89915ab8ac3572",
"title": "Woooa this is working?",
"description": "Yep."
}
}
and also header
{
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjUwMzIwNmM4OTkxNWFiOGFjMzU3MSIsImlhdCI6MTU0NTkyOTUwNCwiZXhwIjoxNTQ2MDEyMzA0fQ.hn4csdGR5w-2yXWVUEmW4wh8U0s5SfWXfClmP0jVgOY"
}
mutation deleteTodo($id: String) {
deleteTodo(id: $id) {
code
message
data {
success
}
}
}
and input
{
"id": "5c20ecda2e62db1ae4d9ff42"
}
and also headers
{
"x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}
I wrote this repo by using my free time. A little motivation and support helps me a lot. If you like this nifty hack you can support me by doing any (or all π ) of the following: