first real commit

This commit is contained in:
Jo 2023-11-24 00:13:48 +01:00
parent 0c96059b29
commit f40e6d51a5
11 changed files with 2631 additions and 6 deletions

60
.eslintrc.js Normal file
View file

@ -0,0 +1,60 @@
module.exports = {
env: {
node: true,
es2021: true,
},
extends: "eslint:recommended",
parserOptions: {
ecmaVersion: 12,
},
rules: {
// Indentation
"indent": ["error", 2], // or 4, depending on your preference
// Quotation Marks
"quotes": ["error", "double", { "allowTemplateLiterals": true }], // or 'single'
// Semicolons
"semi": ["error", "always"],
// Variable Declarations
"init-declarations": "error",
// Variable Naming
"camelcase": "error",
// Unused Variables
"no-unused-vars": "warn",
// Arrow Functions
"prefer-arrow-callback": "error",
"arrow-spacing": "error",
// Block Scoping
"block-scoped-var": "error",
// Function Declarations
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
// Object Shorthand
"object-shorthand": "error",
// Avoid Underscore-Prefixed Names
"no-underscore-dangle": "error",
// Avoid Eval
"no-eval": "error",
// Avoid Using == and !=
"eqeqeq": "error",
// Space Before Function Parenthesis
"space-before-function-paren": ["error", "always"],
// Linebreak Style
"linebreak-style": ["error", "unix"],
// Max Line Length
"max-len": ["error", { "code": 120 }],
},
};

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
# Node modules
node_modules
# Config files
config/config.json
.env

1
Dockerfile Normal file
View file

@ -0,0 +1 @@
# todo: Write Dockerfile

View file

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 Jo
Copyright (c) 2023 Johannes Reckers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

View file

@ -1,6 +1,49 @@
# JET
# Jo's Express Template / JET ;)
JET < Jo's Express Template > is a simple template for creating new express applications.
It includes a basic express setup, configured to suit my needs.
Additionally, there are well documented guidelines that help keep my codebases organized and maintainable.
## Initialize a new project
All you really need to do, is to make a copy of example.env and name it ".env".
Finally, replace the values as required and enjoy your new Express server :)
## Code Structure
One of the most important aspects of a template like this one is, that it gives the developer some kind of base guidelines to work with. This includes, but is not limited to, comments, code dividers, and more...
### Dividers
The dividers that may be commonly seen in this template are as follows:
#### [ ↓ ] Watermark ([ASCII generator](https://textkool.com/en/ascii-art-generator?hl=default&vl=default&font=Train&text=%20Jo))
```js
// _
// o O O _ | | ___
// o | || | / _ \
// TS__[O] _\__/ \___/
// {======|_|"""""|_|"""""|
// ./o--000'"`-0-0-'"`-0-0-'
//
// Code written by «Johannes Reckers»
//------------------------------------------------>
```
#### [ ↓ ] Categories
```js
//------------------------------------------------>
// Category description
//------------------------------------------------>
```
#### [ ↓ ] Sub-Categories
```js
//-------------------<[ x_x ]>
// Sub-Category description
//---[ ↓ ]
```
### Comments
TODO: Add guidelines for comments
## IDE Setup
Here are some general IDE setup tips and plugins which were used during this templates creation.
### VSCodium/Code
#### Plugins
* [Better Comments](https://open-vsx.org/extension/edwinhuish/better-comments-next)
* [ESLint](https://open-vsx.org/extension/dbaeumer/vscode-eslint)

80
app.js Normal file
View file

@ -0,0 +1,80 @@
// _
// o O O _ | | ___
// o | || | / _ \
// TS__[O] _\__/ \___/
// {======|_|"""""|_|"""""|
// ./o--000'"`-0-0-'"`-0-0-'
//
// Code written by «Johannes Reckers»
//------------------------------------------------>
//------------------------------------------------>
// Imports
//------------------------------------------------>
const express = require("express");
const bodyParser = require("body-parser");
const mysql = require("mysql2");
const path = require("path");
const dotenv = require("dotenv");
dotenv.config();
//------------------------------------------------>
// Express initialization & configuration
//------------------------------------------------>
// Initialize the express instance
const app = express();
// Set views directory and engine
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
//------------------------------------------------>
// Middlewares
//------------------------------------------------>
// Use body-parser to get req.body
app.use(bodyParser.urlencoded({ extended: false }));
//------------------------------------------------>
// MySQL connection
//------------------------------------------------>
//! Make extra sure these values are loaded correctly, if you experience any connection issues.
const db = mysql.createConnection({
database: process.env.DB_NAME,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
host: process.env.DB_HOST,
port: process.env.DB_PORT
});
db.connect((error) => {
if (error) {
console.error("[JET] Error connecting to MySQL database:", error);
} else {
console.log("[JET] Database connected successfully");
}
});
//------------------------------------------------>
// Routing
//------------------------------------------------>
const apiRouter = require("./routes/apiRoutes");
app.use("/api", apiRouter);
// Handle home route
app.get("/", (req, res) => {
res.render("layout");
});
//------------------------------------------------>
// Start Express
//------------------------------------------------>
app.listen(process.env.PORT, () => {
console.log(`[JET] started express on http://localhost:${process.env.PORT}`);
});

9
example.env Normal file
View file

@ -0,0 +1,9 @@
# Database
DB_HOST="exampleHost"
DB_PORT=3306
DB_NAME="exampleName"
DB_USER="exampleUser"
DB_PASSWORD="examplePassword"
# Express
PORT=4300

2376
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

31
package.json Normal file
View file

@ -0,0 +1,31 @@
{
"name": "jet",
"version": "0.0.1",
"description": "JET / Jo's Express Template is a template for all of Jo's Express applications!",
"main": "app.js",
"scripts": {
"start": "node .",
"startDev": "nodemon ."
},
"keywords": [
"Express",
"NodeJS",
"JavaScript",
"Docker",
"Template"
],
"author": "Johannes Reckers",
"license": "MIT",
"dependencies": {
"body-parser": "^1.20.2",
"dotenv": "^16.3.1",
"ejs": "^3.1.9",
"express": "^4.18.2",
"mysql2": "^3.6.5",
"path": "^0.12.7"
},
"devDependencies": {
"eslint": "^8.54.0",
"nodemon": "^3.0.1"
}
}

8
routes/apiRoutes.js Normal file
View file

@ -0,0 +1,8 @@
const express = require("express");
const router = express.Router();
router.get("/", (req, res) => {
});
module.exports = router;

11
views/layout.ejs Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JET</title>
</head>
<body>
<h1>Jo's Express Template</h1>
</body>
</html>