Giter Club home page Giter Club logo

express-mysql's Introduction

Core :

  1. Node Js (Backend)

Database :

  1. MySQL (Database)

Packages/Modules :

  1. Express Js (Framework Based on NodeJs)
  2. Express Session (Storing Session Messages)
  3. Dotenv (Environment Variables)
  4. Nodemon (Monitoring Server)
  5. mysql2 (MySQL client for NodeJS)
  6. Multer (Middleware multipart/form-data)

Command :

  1. npm init
  2. npm i express dotenv nodemon mysql2 multer

Basic Routing :

app.method(path, handler);

app.use() bisa menggunakan semua method (GET, POST, dll) sehingga biasa digunakan sebagai middleware

app.use("/", (req, res, next) => {
  res.send('Hello World'); // <-- memberikan respon text kepada client 
});

bisa juga lebih spesifik seperti GET dan POST parameter next hanya bisa digunakan untuk middleware, jadi tidak perlu dituliskan untuk method yang lebih spesifik

app.get("/", (req, res) => {
  res.send('Hello from GET');
});

app.post("/", (req, res) => {
  res.send('Hello from POST');
});

respon yang diberikan bisa juga dalam bentuk html, atau JSON

app.get("/", (req, res) => {
  res.send('<h1>Hello with HTML</h1>');
});

app.post("/", (req, res) => {
  res.json({
    message: "Hello with JSON"
  });
});

untuk menjalankan node server perlu adanya port

app.listen(4000, () => {
  console.log("Server berjalan di port 4000");
});

Struktur Folder Project :

./
|-- node_modules
|-- src/

|-- config/ <-- setup database
|-- controller/ <-- sebuah fungsi yang digunakan didalam routes/
|-- middleware/ <-- middleware
|-- models/ <-- untuk menyimpan fungsi-fungsi call ke DB
|-- routes/ <-- mengumpulkan semua PATH, Users, Products, Sales, dst...
|-- ./index.js <-- main project

HTTP Status Code :

Successful Responses (2xx)

  • 200 OK (GET, PATCH)
  • 201 Created (POST, PUT)

Client Error Responses (4xx)

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowed

Server error responses (5xx)

  • 500 Internal Server Error

Source

express-mysql's People

Contributors

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