-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from hardope/beta
feat: Initial Framework - auto logging
- Loading branch information
Showing
4 changed files
with
117 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,84 @@ | ||
# turboXpress | ||
|
||
`turboXpress` is a Framework & CLI tool designed to help you quickly create and scaffold Express-based projects. It is built on top of ExpressJs and includes built-in logging, static file serving, and JSON request handling by default, so you can focus on building your application. | ||
|
||
## Installation | ||
|
||
Install `turboXpress` globally using npm: | ||
|
||
```bash | ||
npm install -g turbo-xpress | ||
``` | ||
## Usage | ||
1. Initialize a New Express Project | ||
|
||
To create a new folder with your project name, install the required dependencies, and scaffold a basic turboXpress app: | ||
|
||
```bash | ||
npm -g install turbo-xpress | ||
|
||
# usage - command will create a folder with your project name install Express and nodemon | ||
# and write a simple expressJs app | ||
turbo-xpress init <project-name> | ||
``` | ||
|
||
This command will: | ||
|
||
Create a directory with the specified <project-name>. | ||
Install turbo-xpress and nodemon as dependencies. | ||
Automatically create all the necessary files and set up a basic turboXpress application with predefined routes, logging, static server setup, and JSON parsing. | ||
|
||
2. Setup a Project in the Current Folder | ||
|
||
To set up a new project in the current folder (without creating a new one), use this command: | ||
|
||
```bash | ||
|
||
# Setup project in-folder (do not create new folder) | ||
turbo-xpress init <project-name> . | ||
``` | ||
``` | ||
|
||
This will: | ||
|
||
Install turbo-xpress and nodemon in the current directory. | ||
Set up the basic structure of a turboXpress application inside the current folder. | ||
|
||
## Using Your Generated Project | ||
|
||
Once initialized, you can immediately start using the project as you would with a regular Express app. Since turbo-xpress is already imported, the project is ready to run: | ||
|
||
```javascript | ||
|
||
// app.js (auto-generated) | ||
|
||
const app = require('turbo-xpress')(); | ||
|
||
app.get('/', (req, res) => { | ||
res.send('Hello, turboXpress!'); | ||
}); | ||
|
||
const port = 3000; | ||
app.listen(port, () => { | ||
console.log(`Server running on http://localhost:${port}`); | ||
}); | ||
``` | ||
Key Features | ||
|
||
Default Logger: Automatically logs request methods, URLs, status codes, and response times. | ||
Static File Serving: Serves files from the /static directory by default. | ||
JSON Handling: Automatically parses JSON payloads for incoming requests. | ||
|
||
## Project Structure | ||
|
||
After initialization, the project will have the following structure: | ||
|
||
``` | ||
project-name/ | ||
├── node_modules/ | ||
├── package.json | ||
├── app.js | ||
└── static/ | ||
└── index.html (or other static files) | ||
``` | ||
## Features | ||
|
||
Fast Setup: Quickly scaffold your project with one command. | ||
Pre-configured: Built-in logging, static file serving, and JSON parsing. | ||
Flexible: Can be initialized in a new directory or the current working directory. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
function initial() { | ||
return 'TURBO!!!!' | ||
} | ||
const express = require('express'); | ||
|
||
// The main function exported by turboXpress | ||
const turbo_xpress = () => { | ||
const app = express(); | ||
|
||
app.use((req, res, next) => { | ||
const start = Date.now(); | ||
res.on('finish', () => { | ||
const duration = Date.now() - start; | ||
const timestamp = new Date().toISOString(); | ||
console.log(`[${timestamp}] -- ${req.method} -- ${req.url} -- ${res.statusCode} -- ${duration}ms`); | ||
}); | ||
next(); | ||
}); | ||
|
||
app.use(express.json()); | ||
|
||
app.use('/static', express.static('static')); | ||
|
||
const turbo = { | ||
initial | ||
return app; // Return the express apjp object | ||
} | ||
|
||
module.exports = turbo | ||
module.exports = turbo_xpress; |