Giter Site home page Giter Site logo

abenteuerzeit / js-app Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 211 KB

A RESTish API for users and messages endpoints. With Node, Express, Sequelize, and PostgreSQL. The users and messages are regenerated whenever the server starts.

JavaScript 100.00%
crud-application database express-js fake-messages fake-users node-js orm-framework postgresql rest-api routing

js-app's Introduction

Basic app template

  1. nodemon to watch for changes and restart the server
  2. Babel to enable JavaScript feature not enabled in Node.js
  3. Dotenv to load environment variables from a .env file
  4. Express for backend
  5. Middleware
    1. CORS to enable cross-origin requests
    2. Custom middleware for routes

.env

PORT=3000 # Port to run the server on
DATABASE='PostgreSQL-DB-Name' # Name of the database to use
DATABASE_USER='db_username' # Username to connect to the database with
DATABASE_PASSWORD='db_user_password' # Password to connect to the database with
ERASE_DB_ON_SYNC=true # If true, erases the database on sync. It will not if false.
USERS_AMOUNT=100 # Amount of users to generate

User and Messages

  1. User
    1. username
    2. email
    3. name
    4. phone
    5. birthday
    6. password
  2. Message
    1. text
    2. user_id

Data persistance

Each time the server starts, the database is regenerated. To change the database configuration, you can set the following environment variables:

ERASE_DB_ON_SYNC=false

To change how many users with random messages are generated, set the following environment variable to set the number of users to generate:

USERS_AMOUNT=10

The server defaults to a random number of users between 1 and 100. The first generated user is hard coded to the following:

{
    "id": 1,
    "username": "admin",
    "email": "[email protected]",
    "name": "Adrian Mroz",
    "phone": "+1(443)216-9316",
    "birthday": "1988-05-18T00:00:00.000Z",
    "password": "password",
}

And that is all you need to do to change the database configuration.

Route Examples

Run in Postman

GET

curl -X GET http://localhost:3000/users
curl -X GET http://localhost:3000/users/1
curl -X GET http://localhost:3000/messages
curl -X GET http://localhost:3000/messages/1

POST

curl -X POST http://localhost:3000/users -H "Content-Type: application/json" -d 
`{    
    "username": "newuser",
    "email": "[email protected]",
    "name": "Post User",
    "phone": "+1(800)123-1234",
    "birthday": "1950-01-20T00:00:00.000Z",
    "password": "dVmMyp@55word"
}`

curl -X POST http://localhost:3000/messages -H "Content-Type: application/json" -d 
`{    
    "text": "This is a message",
}`

PUT

curl -X PUT http://localhost:3000/users/2 -H "Content-Type: application/json" -d 
`{    
    "username": "newuser",
    "email": "[email protected]"
}`

curl -X PUT http://localhost:3000/messages/2 -H "Content-Type: application/json" -d 
`{    
    "text": "This is a new message",
}` 

DELETE

curl -X DELETE http://localhost:3000/users/2
curl -X DELETE http://localhost:3000/messages/2

js-app's People

Contributors

abenteuerzeit 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.