Code Monkey home page Code Monkey logo

posts's Introduction

posts

Github

  • to have commit smoothly, go to settings -> developer settings -> personal access token -> generate new one and paste in as password when run git push origin branch

Start

  • Connect db to port 5423 on postgres
    • Create tables if not existed at postgres database, they are created.
    • There are models like users posts, there is a module connection define as connection. At router, you import connection, and use connection to connect with each model based on routes hits. On running server, server would check connection module first, then create all models (dbs) connected to it at routes or other places

Debug

  • install remote container

  • select New Dev Container

    • Select Node.js & Postgresql
      • It creates docker-compose which run node first, then create a postgres from image
      • You can add command section at then end
  • Create launch.json as below using nodemon

{
    "version": "0.2.0",
    "configurations": [
    
        {
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "name": "nodemon",
            "program": "${workspaceFolder}/server.js",
            "request": "launch",
            "restart": true,
            "runtimeExecutable": "nodemon",
            "skipFiles": [
                "<node_internals>/**"
            ]
        }
    ]
}

PostgreSQL Get into Container

brew info postgres
  • Postgresql command line
  • When running on container then use this to access postgres
sudo apt-get update
sudo apt-get install -y postgresql-client
psql -h localhost -U postgres -d postgres 
\c DBNAME   -> switch dbs
\l          -> list of databases
\dt         -> show all tables
select * from "Users";   -> show table
  • To get max number of people in each country, use group by country, select Max(anyAttribute) and order by ... DESC
  • docker tag app_image infroger/app_image:1

APIs

users

POST
{
	"name": "Amir khan",
  "email": "[email protected]"
  "bio": ""
}
GET
PUT, to replace the whole resource. several puts is same as one single put
PATH, partialy update resource. several path are different

posts

POST
{
	"name": "Amir khan",
  "email": "[email protected]"
  "bio": ""
}
GET
PUT, to replace the whole resource. several puts is same as one single put
PATH, partialy update resource. several path are different

comments

  • posts/:PostId/comments
POST
{
	"title": "aa",
  "content": "[email protected]"
  "postid": ""
  "like": ""
  "dislike": ""
  "ipaddress": ""
  "city": ""
  country: ""
}
GET /posts/:PostId/comments
# Comments on Comments
post /posts/:postId/comments/:commentid

Config

  • install dotenv and run
config()
  • Then inside process.env you access the .env variables

posts's People

Contributors

anabaei avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.