Go to file
massimiliano c1217cdeba Update 'README.md' 2021-12-04 11:13:24 +00:00
db initial push 2021-12-04 12:07:03 +01:00
example initial push 2021-12-04 12:07:03 +01:00
public initial push 2021-12-04 12:07:03 +01:00
routes initial push 2021-12-04 12:07:03 +01:00
views initial push 2021-12-04 12:07:03 +01:00
.gitignore initial push 2021-12-04 12:07:03 +01:00
LICENSE Initial commit 2021-12-04 11:02:55 +00:00
README.md Update 'README.md' 2021-12-04 11:13:24 +00:00
package-lock.json initial push 2021-12-04 12:07:03 +01:00
package.json initial push 2021-12-04 12:07:03 +01:00
server.js initial push 2021-12-04 12:07:03 +01:00

README.md

Express api server

With this script it is possible to create a (fake)API server connected to a MySQL database. I added 2 example databases that you can easily deploy and test. Of course if you want to connect a new database with different structure, then you need to add/edit some files. All the content in 'routes', 'db', and of course 'example' are as a working example where some code can be recycled to make it work with your existend Database. This could be useful for testing or learning purposes i hope. Feel free to contact me if you want to help improve this code.

To install you need to clone with git clone or download and extract it on you computer/server.

prerequirements:

NodeJS and MariaDB MySQL

tested with:

  • NodeJS v12.22.7
  • npm v8.1.3
  • MariaDB v15.1

configuration of MySQL database and tables(for use with examples)

  • Create a database: CREATE DATABASE api;
  • Change to api database: use api;
  • add two tables:
  • one named 'userlist': CREATE TABLE userlist (email varchar(255) NOT NULL, name varchar(255) NOT NULL, surname varchar(255) NOT NULL, birthDate date NOT NULL, PRIMARY KEY (email));
  • one named 'cats': CREATE TABLE cats (id int(11) NOT NULL AUTO_INCREMENT, name varchar(255) NOT NULL, imageAddress varchar(255) NOT NULL, PRIMARY KEY (id));

installation of the API server

create .env file

use the example.env file (in example folder) and fill the variables for your use case

install npm dependencies

npm install

Start the script

npm start


Once installed visit your host and port with your favourite browser

From there you get further instructions on how to use the API calls and populate the database with the examples