Code Monkey home page Code Monkey logo

practica-backend-nodejs-mongodb's Introduction

Nodepop

A Node JS backend App to sell and buy what you like. To have it running you need Node and MongoDB installed, make sure you have those them installed.

A production deployment can be seen at quantumpop.duckdns.org

React App is deployed at react.quantumpop.duckdns.org

Deployment

Follow these steps to deploy the app.

Install dependencies

    # Move to app directory 'nodepop'
    cd nodepop

    # Install ap dependencies
    npm install

Setup enviroments variables

  • Copy .env.example to .env and customize your local variables.
    cp .env.example .env

Launch MongoDB Server

Make sure your MongoDB is running. In the console move to MongoDB directory and run the following script:

    # Move to the MongoDB directory
    # Then run the script
    ./bin/mongod --dbpath ./data

Initialize the database

  • Move to the nodepop directory and run the init script
    # Move to app directory
    cd nodepop

    # run the script. This adds some Ads and users to your database
    npm run initDB

Deploy in Development environment:

  • In the nodepop folder
    npm run dev

    #or
    npx nodemon

Deploy in Production environment:

  • In the nodepop folder
    npm start

Thumbnail Microservice

This is a microservice used to upload image and convert them in small size. Setup as follow:

    #  Move to Thumbnail Microservice folder inside the nodepop directory
    cd nodepop/ThumbnailMicroservice

    # Then install mircoservices dependencies
    npm install

    # Lauch the service
    npm start

API Documentation

API is accessible at https://52.201.60.201

Testing this APIs

  • From a REST client, perform a login with a register user as follow to authenticate.
    http://quantumpop.duckdns.org/apiv1/login
    # method: POST
    # set these field in the body as x-wwww-form-urlencoded
    # email: [email protected]
    # password: supersecure-1!

    # This should return a JWT token, that needs to bet set in the header of any of the requests
  • To get the list of ads.
    http://quantumpop.duckdns.org/apiv1/ads
    # DO NOT forget authentication
    # method: GET
  • To post a new Ad.
    http://quantumpop.duckdns.org/apiv1/ads
     # DO NOT forget authentication
     # method: POST
     # In the body as 'form-data' add these data, sample
     {
        "article": "Monitor BenQ",
        "onSell": true,
        "price": 300,
        "imageUrl": "monitor-benQ.jpg",
        "tags": [ "work", "lifestyle"],
        "image": <file>
    }

GET /apiv1/ads/

  • List existing ads.
{
     "results": [
         {
            "_id": "63eaac1bd919d8e331535533",
            "article": "Monitor BenQ",
            "onSell": true,
            "price": 300,
            "imageUrl": "monitor-benQ.jpg",
            "tags": [ "work", "lifestyle"]
        },
         ...
     ]
 }

GET /apiv1/ads/tags

  • List existing tags.
{
    "tags": [
        "lifestyle",
        "mobile",
        "motor",
        "work"
    ]
}
  • Filter samples
    // by price
    http://localhost:3000/?price=1000

POST /apiv1/ads/

  • Create new ads. Add an object of this form
{
    "_id": "63eaac1bd919d8e331535533",
    "article": "Monitor BenQ",
    "onSell": true,
    "price": 300,
    "imageUrl": "monitor-benQ.jpg",
    "tags": [ "work", "lifestyle"],
    "image": <file>
},

For more detailed docu check http://localhost:3000/apiv1-docs/

practica-backend-nodejs-mongodb's People

Contributors

njrojas avatar

Watchers

 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.