Skip to content

Commit 4b2593a

Browse files
committed
first commit
0 parents  commit 4b2593a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+6553
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules
2+
tests

README.md

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Node API Logs
2+
3+
Node API Logs is a library that allows Express.js developers to view logs on their server without the need for any third-party services or payments. The library currently only supports Express.js and requires a MongoDB URI.
4+
5+
## Features
6+
7+
- View server logs in a user-friendly interface
8+
- Secure login system for accessing logs
9+
- Simple user management (password reset and user addition through MongoDB)
10+
- Easy integration with existing Express.js applications
11+
12+
## Installation
13+
14+
You can install the library using npm or yarn:
15+
16+
```bash
17+
npm i node-api-logs
18+
# or
19+
yarn add node-api-logs
20+
```
21+
22+
To use the library, you need to import the
23+
24+
```bash
25+
createApp
26+
27+
import {createApp} from "node-api-logs";
28+
29+
createApp(app,"mongo uri");
30+
```
31+
function and provide your Express app instance along with a MongoDB URI.
32+
33+
Here’s a basic example of how to use the library in your index.ts file:
34+
35+
```bash
36+
import express, { Application, Request, Response } from 'express';
37+
import cors from 'cors';
38+
import helmet from 'helmet';
39+
import dotenv from 'dotenv';
40+
import expressFileUpload from 'express-fileupload';
41+
import path from 'path';
42+
import { createApp } from "node-api-logs";
43+
44+
// Configurations
45+
dotenv.config();
46+
import './config/database';
47+
import './config/redis';
48+
import AppRoutes from './modules/app/app.route';
49+
import { formatReq } from './middlewares/helpers.middleware';
50+
import logger from './config/logger';
51+
import morganMiddleware from './middlewares/morgan.middleware';
52+
53+
// Boot express
54+
const app: Application = express();
55+
const port = process.env.PORT || 3000;
56+
const base: string = process.env.base_url ?? '/staging/api/v1';
57+
58+
// Middlewares
59+
app.use(cors());
60+
app.use(helmet());
61+
app.use(expressFileUpload({ createParentPath: true, useTempFiles: true }));
62+
app.use(express.urlencoded({ extended: false }));
63+
app.use(express.json());
64+
app.use('/docs', express.static(path.join(__dirname, 'docs')));
65+
app.use(formatReq);
66+
app.use(morganMiddleware);
67+
68+
// Set up Node API Logs
69+
createApp(app, "your-mongodb-uri");
70+
71+
// Application routing
72+
app.get('/', (req: Request, res: Response) => {
73+
res.status(200).send({ data: 'BACKEND Application' });
74+
});
75+
app.use(base, AppRoutes);
76+
77+
// Start server
78+
app.listen(port, () => logger.info(`Server is listening on port ${port}!`));
79+
80+
// Handle unhandled promise rejections and exceptions
81+
process.on('unhandledRejection', (err: any) => {
82+
logger.error('Unhandled Rejection', err);
83+
});
84+
85+
process.on('uncaughtException', (err: any) => {
86+
logger.error(err.message, err);
87+
});
88+
```
89+
90+
To access the logs, visit:
91+
92+
```bash
93+
http://localhost:PORT/logs/login
94+
```
95+
### User Management
96+
97+
To change a user's password:
98+
99+
1. Go to [bcrypt-generator](https://bcrypt-generator.com) to generate a new password.
100+
2. Manually update the user's password in the MongoDB database.
101+
102+
To add a new user:
103+
104+
1. Go to your `users` collection in MongoDB.
105+
2. Click on "Add Data" and select "Insert Document."
106+
3. Click "Insert" and then edit the new document to add the user's email.
107+
4. Once the user visits `http://localhost:PORT/logs/login` and inputs their email and password, the password will be automatically set for them.
108+
109+
To remove a user:
110+
111+
Simply delete the user's record from the database.
112+
113+
### Contributing
114+
115+
Contributions are welcome! If you'd like to contribute, please follow these steps:
116+
117+
1. Fork the repository.
118+
2. Create a new branch (`git checkout -b feature-branch`).
119+
3. Make your changes.
120+
4. Commit your changes (`git commit -m 'Add feature'`).
121+
5. Push to the branch (`git push origin feature-branch`).
122+
6. Open a pull request.
123+
124+
Please make sure to update tests as appropriate.
125+
126+
### Contact
127+
128+
For issues or questions, feel free to contact me at:
129+
130+
131+
- GitHub: [Ugochukwudev](https://github.com/ugochukwudev)
132+
133+
### License
134+
135+
This project is licensed under the MIT License. See the `LICENSE` file for details.

dist/controllers/api.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { Request, Response } from 'express';
2+
export declare const getLogs: (req: Request, res: Response) => Promise<void>;
3+
export declare const getLogById: (req: Request, res: Response) => Promise<Response<any, Record<string, any>> | undefined>;
4+
//# sourceMappingURL=api.d.ts.map

dist/controllers/api.d.ts.map

+1
Original file line numberDiff line numberDiff line change

dist/controllers/api.js

+67
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/controllers/api.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/controllers/auth.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Request, Response } from 'express';
2+
export declare const loginUser: (req: Request, res: Response) => Promise<Response<any, Record<string, any>> | undefined>;
3+
//# sourceMappingURL=auth.d.ts.map

dist/controllers/auth.d.ts.map

+1
Original file line numberDiff line numberDiff line change

dist/controllers/auth.js

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/controllers/auth.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/db.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
declare const connectMongo: (uri: string, name?: string) => Promise<void>;
2+
export default connectMongo;
3+
//# sourceMappingURL=db.d.ts.map

dist/db.d.ts.map

+1
Original file line numberDiff line numberDiff line change

dist/db.js

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/db.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Application } from 'express';
2+
export declare const createApp: (app: Application, mongoUri: string) => void;
3+
//# sourceMappingURL=index.d.ts.map

dist/index.d.ts.map

+1
Original file line numberDiff line numberDiff line change

0 commit comments

Comments
 (0)