1.1.8 • Published 7 months ago

@zer0cheros/simple-react-server v1.1.8

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

Zer0cheros

simple-react-server

A method for testing your React application against a simple and minimal backend API server. The server is a mix of express package and knex package. Simplifying coding for a more enjoyable experience.

  • Don´t use in production!!
  • Only for development!!

When you install the package, it automatically creates a 'server.ts' file in your '/src' folder.

Server-side

import Server from '@zer0cheros/simple-react-server'

const server = new Server(8080)

//Config DB with you own credentials
server.connect('db', {client: "mysql", host: '127.0.0.1', port: 3306, user: 'root', password: 'password'})

// When no specific request is made, a default JSON response will be presented.
server.Get('/')

//A query to retrieve all data from the 'users' table in the database
server.Get('/users', true).DB('users')

// A query to retrieve data from the 'users' table in the database, with a specific id
server.Get('/users', false, true).DB('users').ID(4) 

//Starts application
server.start()

Client

//simple example of using client and server
import { useState, useEffect } from 'react'
import Client from '@zer0cheros/simple-react-server/client'


function App() {
  const [users, setUsers] = useState([]) //your types here
  const client = new Client('http://localhost:8080')
  useEffect(()=>{
    client.Get('/users').then((res)=>{
      setUsers(res) 
    })
  },[])
  return (
    <div>
      {users.map((user:any)=>(
        <div key={user.id}>
          <h1>{user.name}</h1>
          <h2>{user.email}</h2>
        </div>
      )
      )}
    </div>
  )
}

export default App

Installation

$ npm install @zer0cheros/simple-react-server

Recommended for more optimized development.

  1. Installing script for setting up automation tools.
$ npm install npm-run-all nodemon -g
  1. Add this to your package.json
"scripts": {
  "server-build": "tsc ./src/server.ts && move src\\server.js src\\server.cjs",
  "server-run": "nodemon ./src/server.cjs",
  "server-start": "npm-run-all --parallel server-build server-run"
}

Features

  • Easy setup
  • Less code
  • Workning upon express

People

The teacher behind is Christian

License

MIT

1.1.8

7 months ago

1.1.7

7 months ago

1.1.6

7 months ago

1.1.5

7 months ago

1.1.4

7 months ago

1.1.3

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.16

7 months ago

1.0.14

7 months ago

1.0.13

7 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago