Skip to content

mguardarini/api-rest-es6-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

·GitHub license npm version

Express & ES6 REST API Boilerplate

This is a straightforward boilerplate for building REST APIs with ES6 and Express.

Tip: If you are using Mongoose, you can automatically expose your Models as REST resources using restful-mongoose.

# clone it
git clone [email protected]:mguardarini/api-rest-es6-express.git
cd express-es6-rest-api

# Make it your own
rm -rf .git && git init && npm init

# Install dependencies
npm install

# Start development live-reload server
PORT=8080 npm run dev

# Start production server:
PORT=8080 npm start

Getting Started

Now, the most important part of all. Get an SSL certificate. A standard SSL certificate comes with two important files, Primary certificate and Intermediate certificate. To get an SSL, you will have to generate a CSR from your server for validation. Also we need to generate a key (private key) to maintain an HTTPS connection with the server. Running the following command in a linux environment will get us our desired mydomain.csr and private.key files.

openssl req -new -newkey rsa:2048 -nodes -out mydomain.csr -keyout private.key

Generate a Self-Signed Certificate from an Existing Private Key and CSR

Use this method if you already have a private key and CSR, and you want to generate a self-signed certificate with them.

This command creates a self-signed certificate (domain.crt) from an existing private key (domain.key) and (domain.csr):

Primary Certificate

`` openssl x509 -req -days 365 -in mydomain.csr -signkey private.key -out primary.crt

``

Intermediate Certificate

`` openssl x509 -req -days 365 -in mydomain.csr -signkey private.key -out intermediate.crt

``

The option(-days) specifies that the certificate will be valid for 365 days

Create Test Database

For this example i using MySQL database, so, to test you need to create a database with the name "Test" and create one table with the name "Telemetry".

  1. CREATE DATABASE Test;
  2. use Test;
  3. CREATE TABLE Telemetry (hardwareId varchar(30), date dateTime, id int auto_increment primary key);

References:

License

  • MIT