Giter Club home page Giter Club logo

saisilinus / node-express-mongoose-typescript-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
318.0 318.0 93.0 628 KB

A boilerplate for making production-ready RESTful APIs using Node.js, TypeScript, Express, and Mongoose

License: MIT License

Shell 0.17% Dockerfile 0.34% JavaScript 2.53% TypeScript 96.96%
boilerplate express express-boilerplate hot-reload mongodb mongoose node-boilerplate nodejs rest-api template typescript typescript-express-boilerplate

node-express-mongoose-typescript-boilerplate's Issues

Hot reload when dev mode

I think maybe use should add a package "concurrently" as devDependencies.
And change dev script like this to achieve Hot Reload as dev script.

PS: your command "yarn compile:watch" maybe wrong when include "src".

`"dev": "concurrently "yarn compile:watch" "yarn pre:dev"",

"pre:dev": "cross-env NODE_ENV=development nodemon --experimental-modules --es-module-specifier-resolution=node dist/index.js",

"compile:watch": "tsc --build --watch",`

"No users found with this email" Message should be hidden

An attacker may use the "forgot-password" request to know whether an account with the targeted email exists or not.
Whether the email is in use or not, the requestor should probably receive the same response.
Something like this:

export const generateResetPasswordToken = async (email: string): Promise<string> => {
  const user = await userService.getUserByEmail(email);
  if (!user) {
    // While it's an error, the form submitter will not know and will receive a pseudo-success message
    throw new ApiError(
      httpStatus.OK,
      'If this email is registered, it will receive the instructions on resetting the password.'
    );
  }
  const expires = moment().add(config.jwt.resetPasswordExpirationMinutes, 'minutes');
  const resetPasswordToken = generateToken(user.id, expires, tokenTypes.RESET_PASSWORD);
  await saveToken(resetPasswordToken, user.id, expires, tokenTypes.RESET_PASSWORD);
  return resetPasswordToken;
};

http-status and helmet types are missing

Describe the bug
When installing the project, the http-status and helmet types are missing.

To Reproduce
Steps to reproduce the behavior:

  1. Clone the project
  2. Go to app.ts file
  3. See types errors

Expected behavior
No type errors should be shown

Screenshots
image

Desktop (please complete the following information):

  • OS: [e.g. iOS] - Windows
  • Browser [e.g. chrome, safari] - No browser needed, but vscode
  • Version [e.g. 22] - No browser needed, but vscode

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6] - No browser needed, but vscode
  • OS: [e.g. iOS8.1] - No browser needed, but vscode
  • Browser [e.g. stock browser, safari] - No browser needed, but vscode
  • Version [e.g. 22] - No browser needed, but vscode

Additional context
This PR should fix this: #53

FRONT_URL as a required environmental variable

Adding this makes it easy to use the correct link in development vs production.
Also changing it along with the other options is easier.

Example:

const resetPasswordUrl = `http://${config.frontUrl}/reset-password?token=${token}`;

Running yarn docker:dev results in error while composing node-app

Problem:

When I try to dockerize the application the composing errors on the node-app part. No directory is created and nothing happens. Besides the console showing the key word error not further stack trace is displayed. So I would be interested if this is a general issue or if my environment is the issue.

Environment:

Module Version
node v16.15.1
yarn v1.22.19
npm v8.18.0

Device

Type MacBook Pro (16", 2021)
OS macOS Monterey v12.6
Chip Apple M1 Pro 

Steps to reproduce issue

$ git clone https://github.com/saisilinus/node-express-mongoose-typescript-boilerplate.git
$ yarn install
$ cp .env.example .env
$ yarn docker:dev

Error using alias path

Hi,
thanks a lot for this template, very good work.

I try to use alias path in the project, I add this in tsconfig.json under compilerOptions:
"paths": { "~/*": ["./src/*"], },

but when run yarn dev I get this error:

[0]
[1] node:internal/errors:490
[1] ErrorCaptureStackTrace(err);
[1] ^
[1]
[1] Error [ERR_MODULE_NOT_FOUND]: Cannot find package '~' imported from /stuff/dist/index.js
[1] at new NodeError (node:internal/errors:399:5)
[1] at packageResolve (node:internal/modules/esm/resolve:889:9)
[1] at moduleResolve (node:internal/modules/esm/resolve:938:20)
[1] at defaultResolve (node:internal/modules/esm/resolve:1153:11)
[1] at nextResolve (node:internal/modules/esm/loader:163:28)
[1] at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
[1] at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
[1] at ModuleWrap. (node:internal/modules/esm/module_job:77:40)
[1] at link (node:internal/modules/esm/module_job:76:36) {
[1] code: 'ERR_MODULE_NOT_FOUND'
[1] }

I have tried several solutions but none have solved the problem. could anyone help me.

thank you very much

Paginate: (schema: Schema) type error

Hi,
I'm updated all package for this project, but after update mongoose i get error type, please check issue and if you can helped to fix this problem.

user.model.ts(58,19): error TS2345: Argument of type '(schema: Schema) => void' is not assignable to parameter of type 'PluginFunction<IUserDoc, IUserModel, any, any, any, any>'.
[0] Types of parameters 'schema' and 'schema' are incompatible.
[0] Type 'Schema<IUserDoc, IUserModel, any, any, any, any, "type", IUserDoc>' is not assignable to type 'Schema<any, Model<any, any, any, any, any>, {}, {}, {}, {}, "type", { [x: string]: any; }>'.
[0] Types of property 'obj' are incompatible.
[0] Type '{ _id?: SchemaDefinitionProperty | undefined; __v?: SchemaDefinitionProperty | undefined; id?: SchemaDefinitionProperty | undefined; ... 5 more ...; isEmailVerified?: SchemaDefinitionProperty<...> | undefined; }' is not assignable to type '{ [path: string]: SchemaDefinitionProperty; } | { [x: string]: SchemaDefinitionProperty | undefined; }'.
[0] Type '{ _id?: SchemaDefinitionProperty | undefined; __v?: SchemaDefinitionProperty | undefined; id?: SchemaDefinitionProperty | undefined; ... 5 more ...; isEmailVerified?: SchemaDefinitionProperty<...> | undefined; }' is not assignable to type '{ [x: string]: SchemaDefinitionProperty | undefined; }'.
[0] Property 'isEmailVerified' is incompatible with index signature.
[0] Type 'SchemaDefinitionProperty' is not assignable to type 'SchemaDefinitionProperty | undefined'.
[0] Type 'false' is not assignable to type 'SchemaDefinitionProperty | undefined'.

App crashing at the very beginning.

Describe the bug
The app crashes when I start it.

To Reproduce
Steps to reproduce the behavior:

  1. npx create-nodejs-ts-app back
  2. cd back
  3. yarn dev
  4. See error (screenshot)

Expected behavior
The app should work as expected.

Screenshots
Capture d’écran 2022-11-23 à 17 10 34

Desktop :

  • OS: MacOS Monterey (12.3)

Additional context
This is the same behaviour with yarn start. I also tried to yarn compile first but it didn't change anything.

Thanks for your help !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.