create-express-kickstart 1.2.2 → 1.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +0,0 @@
1
- {
2
- "name": "test-app",
3
- "version": "1.0.0",
4
- "description": "test-desc",
5
- "main": "src/server.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "node src/server.js",
9
- "dev": "nodemon src/server.js",
10
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
11
- },
12
- "imports": {
13
- "#*": "./src/*"
14
- },
15
- "keywords": [
16
- "express",
17
- "node",
18
- "api"
19
- ],
20
- "author": "me",
21
- "license": "ISC",
22
- "dependencies": {
23
- "bcryptjs": "^3.0.3",
24
- "dotenv": "^17.3.1",
25
- "express": "^5.2.1",
26
- "jsonwebtoken": "^9.0.3"
27
- },
28
- "devDependencies": {
29
- "jest": "^30.2.0",
30
- "nodemon": "^3.1.14",
31
- "supertest": "^7.2.2"
32
- }
33
- }
@@ -1,28 +0,0 @@
1
- import express from "express";
2
- import { errorHandler } from "#middlewares/errorHandler.middleware.js";
3
-
4
- // Import routers
5
- import authRouter from "#routes/auth.routes.js";
6
- import healthcheckRouter from "#routes/healthcheck.routes.js";
7
-
8
- const app = express();
9
-
10
-
11
-
12
-
13
-
14
- // Payload sizes and forms
15
- app.use(express.json({ limit: "16kb" }));
16
- app.use(express.urlencoded({ extended: true, limit: "16kb" }));
17
- app.use(express.static("public"));
18
-
19
- // -------- API ROUTES ---------
20
- // Mount routers
21
- app.use("/api/v1/auth", authRouter);
22
- app.use("/api/v1/healthcheck", healthcheckRouter);
23
-
24
- // Global Error Handler
25
- // Always add this as the very last middleware
26
- app.use(errorHandler);
27
-
28
- export { app };
@@ -1,5 +0,0 @@
1
- export const authController = {
2
- login: (req, res) => res.json({ message: "Login logic goes here." }),
3
- register: (req, res) => res.json({ message: "Register logic goes here." }),
4
- profile: (req, res) => res.json({ message: "Protected profile data." })
5
- };
@@ -1,17 +0,0 @@
1
- import { ApiError } from "#utils/ApiError.js";
2
- import { ApiResponse } from "#utils/ApiResponse.js";
3
- import { asyncHandler } from "#utils/asyncHandler.js";
4
-
5
- const healthcheck = asyncHandler(async (req, res) => {
6
- // Basic health check
7
- return res
8
- .status(200)
9
- .json(new ApiResponse(200, { status: "OK", timestamp: Date.now() }, "App is running smoothly"));
10
- });
11
-
12
- const triggerError = asyncHandler(async (req, res) => {
13
- // Dummy route to test the global error handler
14
- throw new ApiError(400, "This is a custom error thrown for testing purposes.");
15
- });
16
-
17
- export { healthcheck, triggerError };
@@ -1,5 +0,0 @@
1
- export const authMiddleware = (req, res, next) => {
2
- // Add JWT verification logic here
3
- console.log('Verifying token...');
4
- next();
5
- };
@@ -1,37 +0,0 @@
1
- import { ApiError } from '#utils/ApiError.js';
2
-
3
- /**
4
- * Global Error Handler Middleware
5
- * @param {Error} err
6
- * @param {Request} req
7
- * @param {Response} res
8
- * @param {NextFunction} next
9
- */
10
- const errorHandler = (err, req, res, next) => {
11
- let error = err;
12
-
13
- // If the error is not an instance of ApiError, transform it into one
14
- if (!(error instanceof ApiError)) {
15
- const statusCode = error.statusCode ? error.statusCode : 500;
16
- const message = error.message || "Internal Server Error";
17
-
18
- error = new ApiError(
19
- statusCode,
20
- message,
21
- error?.errors || [], // Pass down any validation errors
22
- err.stack // Keep the original stack trace
23
- );
24
- }
25
-
26
- // Now format the consistent response
27
- const response = {
28
- ...error,
29
- message: error.message,
30
- ...(process.env.NODE_ENV === 'development' ? { stack: error.stack } : {})
31
- };
32
-
33
- // Send the JSON response
34
- return res.status(error.statusCode).json(response);
35
- };
36
-
37
- export { errorHandler };
@@ -1,18 +0,0 @@
1
- //example-model.js
2
- import mongoose from "mongoose";
3
-
4
- const exampleSchema = new mongoose.Schema({
5
- name: {
6
- type: String,
7
- required: [true, "Name is required"],
8
- },
9
- age: {
10
- type: Number,
11
- required: [true, "Age is required"],
12
- },
13
- email: {
14
- type: String,
15
- required: [true, "Email is required"],
16
- unique: true,
17
- },
18
- });
@@ -1,11 +0,0 @@
1
- import { Router } from 'express';
2
- import { authController } from '../controllers/auth.controller.js';
3
- import { authMiddleware } from '../middlewares/auth.middleware.js';
4
-
5
- const router = Router();
6
-
7
- router.post('/login', authController.login);
8
- router.post('/register', authController.register);
9
- router.get('/profile', authMiddleware, authController.profile);
10
-
11
- export default router;
@@ -1,9 +0,0 @@
1
- import { Router } from 'express';
2
- import { healthcheck, triggerError } from '#controllers/healthcheck.controller.js';
3
-
4
- const router = Router();
5
-
6
- router.route('/').get(healthcheck);
7
- router.route('/error').get(triggerError);
8
-
9
- export default router;
@@ -1,20 +0,0 @@
1
- import dotenv from "dotenv";
2
- import { app } from "#app.js";
3
-
4
- // Load environment variables from .env file
5
- dotenv.config({
6
- path: './.env'
7
- });
8
-
9
-
10
- const PORT = process.env.PORT || 8000;
11
-
12
- app.listen(PORT, () => {
13
- console.log(`Server is running at port : ${PORT}`);
14
- });
15
-
16
- process.on("unhandledRejection", (err) => {
17
- console.log("UNHANDLED REJECTION! Shutting down...");
18
- console.log(err.name, err.message);
19
- process.exit(1);
20
- });
@@ -1,23 +0,0 @@
1
- class ApiError extends Error {
2
- constructor(
3
- statusCode,
4
- message = "Something went wrong",
5
- errors = [],
6
- stack = ""
7
- ) {
8
- super(message);
9
- this.statusCode = statusCode;
10
- this.data = null;
11
- this.message = message;
12
- this.success = false;
13
- this.errors = errors;
14
-
15
- if (stack) {
16
- this.stack = stack;
17
- } else {
18
- Error.captureStackTrace(this, this.constructor);
19
- }
20
- }
21
- }
22
-
23
- export { ApiError }
@@ -1,10 +0,0 @@
1
- class ApiResponse {
2
- constructor(statusCode, data, message = "Success") {
3
- this.statusCode = statusCode;
4
- this.data = data;
5
- this.message = message;
6
- this.success = statusCode < 400; // Success is true if status code is not an error level
7
- }
8
- }
9
-
10
- export { ApiResponse }
@@ -1,7 +0,0 @@
1
- const asyncHandler = (requestHandler) => {
2
- return (req, res, next) => {
3
- Promise.resolve(requestHandler(req, res, next)).catch((err) => next(err));
4
- };
5
- };
6
-
7
- export { asyncHandler };
@@ -1 +0,0 @@
1
- export const DB_NAME = "my_app_db";
@@ -1,12 +0,0 @@
1
- import request from 'supertest';
2
- import { app } from '../src/app.js';
3
-
4
- describe('Healthcheck API', () => {
5
- it('should return 200 OK', async () => {
6
- const response = await request(app).get('/api/v1/healthcheck');
7
-
8
- expect(response.status).toBe(200);
9
- expect(response.body.success).toBe(true);
10
- expect(response.body.message).toBe('Api is runing properly');
11
- });
12
- });
package/test-runner.js DELETED
@@ -1,39 +0,0 @@
1
- import { spawn } from 'child_process';
2
-
3
- const run = () => {
4
- console.log('Running CLI locally with pre-filled inputs...');
5
- const child = spawn('node', ['./bin/cli.js', 'test-app'], {
6
- stdio: ['pipe', 'inherit', 'inherit']
7
- });
8
-
9
- const inputs = [
10
- '\n', // package json name
11
- 'test-desc\n', // description
12
- 'me\n', // author
13
- 'n\n', // Mongoose
14
- 'n\n', // CORS
15
- 'n\n', // Helmet
16
- 'n\n', // cookie-parser
17
- 'n\n', // Pino
18
- 'n\n', // Rate Limiting
19
- 'y\n', // dotenv
20
- 'n\n', // prettier
21
- 'npm\n', // PM
22
- 'n\n', // Git
23
- 'n\n', // Docker
24
- 'y\n', // Auth
25
- 'y\n', // ESM
26
- 'y\n' // Jest
27
- ];
28
- let i = 0;
29
- const interval = setInterval(() => {
30
- if (i < inputs.length) {
31
- child.stdin.write(inputs[i]);
32
- i++;
33
- } else {
34
- clearInterval(interval);
35
- child.stdin.end();
36
- }
37
- }, 200);
38
- }
39
- run();