This project is a REST API template built with Express.js. It serves as a starting point for building RESTful APIs using Node.js and Express.
Clone the repository:
git clone https://github.com/Emsa001/rest-api-template.git
cd rest-api-template
Install dependencies:
npm install
Copy and change the values of .env and .keys.json as needed:
cp .env.example .env
cp .keys.example.json .keys.json
Start the development server:
npm start
Sequelize allows you to manage multiple databases effortlessly. You can add as many databases as you need, but ensure that you keep the models for each database separate.
// Initialize the first database
const db1 = new Database("db1", { dialect: "sqlite", storage: "./database1.sqlite", logging: false });
// Initialize database with models in directory ./models1
await db1.init("./models1");
// Initialize the second database
const db2 = new Database("db2",{
dialect: "mysql",
host: process.env.DB_HOST,
database: process.env.DB_DATABASE,
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
});
// Initialize database with models in directory ./models2
await db2.init("./models2");
GET /public/hello/:user
Parameter | Type | Description |
---|---|---|
user |
string |
Required Username |
GET /public/hello2?user=...
Parameter | Type | Description |
---|---|---|
user |
string |
Required Username |
GET /auth/hello
HEADER | Type | value |
---|---|---|
authorization |
Bearer Token |
superSecretKey1 |
- Structured REST API template
- Multiple Database Support
- Bearer authorization with permissions
- Error Handling with saving to logs
- Requestss logging