Skip to content

Commit f34b486

Browse files
authored
Merge pull request #1 from hardope/beta
feat: Initial Framework - auto logging
2 parents 7b784b4 + 1b299be commit f34b486

File tree

4 files changed

+117
-29
lines changed

4 files changed

+117
-29
lines changed

README.md

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,84 @@
11
# turboXpress
22

3+
`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.
4+
5+
## Installation
6+
7+
Install `turboXpress` globally using npm:
8+
9+
```bash
10+
npm install -g turbo-xpress
11+
```
12+
## Usage
13+
1. Initialize a New Express Project
14+
15+
To create a new folder with your project name, install the required dependencies, and scaffold a basic turboXpress app:
16+
317
```bash
4-
npm -g install turbo-xpress
518

6-
# usage - command will create a folder with your project name install Express and nodemon
7-
# and write a simple expressJs app
819
turbo-xpress init <project-name>
20+
```
21+
22+
This command will:
23+
24+
Create a directory with the specified <project-name>.
25+
Install turbo-xpress and nodemon as dependencies.
26+
Automatically create all the necessary files and set up a basic turboXpress application with predefined routes, logging, static server setup, and JSON parsing.
27+
28+
2. Setup a Project in the Current Folder
29+
30+
To set up a new project in the current folder (without creating a new one), use this command:
31+
32+
```bash
933

10-
# Setup project in-folder (do not create new folder)
1134
turbo-xpress init <project-name> .
12-
```
35+
```
36+
37+
This will:
38+
39+
Install turbo-xpress and nodemon in the current directory.
40+
Set up the basic structure of a turboXpress application inside the current folder.
41+
42+
## Using Your Generated Project
43+
44+
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:
45+
46+
```javascript
47+
48+
// app.js (auto-generated)
49+
50+
const app = require('turbo-xpress')();
51+
52+
app.get('/', (req, res) => {
53+
res.send('Hello, turboXpress!');
54+
});
55+
56+
const port = 3000;
57+
app.listen(port, () => {
58+
console.log(`Server running on http://localhost:${port}`);
59+
});
60+
```
61+
Key Features
62+
63+
Default Logger: Automatically logs request methods, URLs, status codes, and response times.
64+
Static File Serving: Serves files from the /static directory by default.
65+
JSON Handling: Automatically parses JSON payloads for incoming requests.
66+
67+
## Project Structure
68+
69+
After initialization, the project will have the following structure:
70+
71+
```
72+
73+
project-name/
74+
├── node_modules/
75+
├── package.json
76+
├── app.js
77+
└── static/
78+
└── index.html (or other static files)
79+
```
80+
## Features
81+
82+
Fast Setup: Quickly scaffold your project with one command.
83+
Pre-configured: Built-in logging, static file serving, and JSON parsing.
84+
Flexible: Can be initialized in a new directory or the current working directory.

bin/turbo.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ async function initProject(projectName, currentDir, isCurrentFolder) {
2929
}
3030
}
3131

32-
// Create an index.js file
32+
// Create an index.js file using turxpress
3333
const indexContent = `
34-
const express = require('express');
35-
const app = express();
34+
const turbo_xpress = require('turbo-xpress');
35+
const app = turbo_xpress();
3636
const PORT = process.env.PORT || 3000;
3737
3838
app.get('/', (req, res) => {
39-
res.send('Hello, TurboXpress!');
39+
res.send('Hello, turbo-xpress!');
4040
});
4141
4242
app.listen(PORT, () => {
@@ -54,11 +54,11 @@ app.listen(PORT, () => {
5454
process.chdir(projectPath); // Change the current working directory to the new project folder
5555
}
5656

57-
console.log(colors.yellow('Initializing npm and installing Express...'));
57+
console.log(colors.yellow('Initializing npm and installing turboxpress...'));
5858

59-
// Initialize npm and install Express
59+
// Initialize npm and install turbo-xpress
6060
await initNpm();
61-
await installExpress();
61+
await installturbo_xpress();
6262

6363
// Modify package.json to add custom start scripts
6464
await updatePackageJson();
@@ -72,21 +72,22 @@ app.listen(PORT, () => {
7272
function initNpm() {
7373
return new Promise((resolve, reject) => {
7474
exec('npm init -y', (error, stdout, stderr) => {
75-
if (error) {
76-
console.error(colors.red(`Error initializing npm: ${stderr}`));
77-
reject(error);
78-
return;
79-
}
80-
resolve();
75+
if (error) {
76+
console.error(colors.red(`Error initializing npm: ${stderr}`));
77+
reject(error);
78+
return;
79+
}
80+
resolve();
8181
});
8282
});
8383
}
8484

85-
function installExpress() {
85+
// Function to install turboxpress using npm link and install nodemon
86+
function installturbo_xpress() {
8687
return new Promise((resolve, reject) => {
87-
exec('npm install express nodemon', (error, stdout, stderr) => {
88+
exec('npm install turbo-xpress nodemon', (error, _stdout, stderr) => {
8889
if (error) {
89-
console.error(colors.red(`Error installing Express: ${stderr}`));
90+
console.error(colors.red(`Error linking turbxpress or installing nodemon: ${stderr}`));
9091
reject(error);
9192
return;
9293
}
@@ -126,5 +127,5 @@ if (command === 'init' && projectName) {
126127
// Pass the currentDir if using "."
127128
initProject(isCurrentFolder ? currentDir : projectName, currentDir, isCurrentFolder);
128129
} else {
129-
console.log(colors.red('Invalid command. Use "turbo init <project-name>" or "turbo init <project-name> ."'));
130+
console.log(colors.red('Invalid command. Use "turb-xpresss init <project-name>" or "turbo-xpress init <project-name> ."'));
130131
}

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
1-
function initial() {
2-
return 'TURBO!!!!'
3-
}
1+
const express = require('express');
2+
3+
// The main function exported by turboXpress
4+
const turbo_xpress = () => {
5+
const app = express();
6+
7+
app.use((req, res, next) => {
8+
const start = Date.now();
9+
res.on('finish', () => {
10+
const duration = Date.now() - start;
11+
const timestamp = new Date().toISOString();
12+
console.log(`[${timestamp}] -- ${req.method} -- ${req.url} -- ${res.statusCode} -- ${duration}ms`);
13+
});
14+
next();
15+
});
16+
17+
app.use(express.json());
18+
19+
app.use('/static', express.static('static'));
420

5-
const turbo = {
6-
initial
21+
return app; // Return the express apjp object
722
}
823

9-
module.exports = turbo
24+
module.exports = turbo_xpress;

0 commit comments

Comments
 (0)