Coder Social home page Coder Social logo

tillhoffmann1411 / node-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 796 KB

A boilerplate template for NodeJS projects.

License: MIT License

Dockerfile 0.74% TypeScript 99.04% Shell 0.22%
node typescript express docker boilerplate-template node-boilerplate nodejs nginx nginx-proxy passportjs

node-boilerplate's Introduction

node-boilerplate

A boilerplate template for NodeJS projects.

Setup

  1. Create a .env file in the root directory with following settings:
PORT=80

MONGO_USERNAME=
MONGO_PASSWORD=
MONGO_PORT=27017
MONGO_DB=mongodb

JWT_KEY=
COOKIE_SECRET=  
  1. With docker-compose up you can start the server.
  2. Test your running backend Postman API documentation

What belongs where

Folder Contains
config Configurations for packages.
controllers Logic behind the routes but delegate the main logic to services. Handle here errors.
interfaces Implement your typescript interfaces here.
middleware Express middlewares are here implemented.
models Mongoose models are here defined
routes Define your different routes here.
services Main logic divided according to the data they use. This is where database accesses take place.

Feel free to use commit emojis for some color and easy to understand commit messages.

node-boilerplate's People

Contributors

tillhoffmann1411 avatar vforsmann avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

vforsmann

node-boilerplate's Issues

jwt expires

The Token Object of JWT contains expires, but the cookie must also, otherwise its just working for one session.

node-image noch buggy im Bezug auf npm

Irgendwann habe ich in offiziellen Vorträgen rausgefunden, dass für jegliche externe Bibliothek die man in den $PATH installiert ein best-practise ist, diese per Entrypoint aufzurufen.
Das hat den Vorteil, dass dann die Volumes schon gemounted sind, man muss also vorher kein Copy mehr machen und das wird ggf. vom Volume überschrieben (das ist aktuell der Fall). Außerdem werden beim Image-bauen teilweise Systembibliotheken vom HOST im RUN verwendet, was zu ekeligen Fehlern führen kann.
Hier also mal ein anderes Herangehen, damit hatte ich bisher die allerwenigsten Probleme:

Dockerfile

FROM node

ADD ./node_startup.sh /
RUN ["chmod", "+x", "/node_startup.sh"]

EXPOSE 3000

ENTRYPOINT ["/node_startup.sh"]

CMD [ "npm", "run", "start:watch" ]

node_startup.sh

#!/bin/bash

npm install
npm run build

exec "$@"

Auf macOS und Linux getestet, funktioniert problemlos. Windows... your thing ;)

signup 2x with same email

When singing up two times with the same email nodejs throws mongodb error as follows:

image

Maybe wanted?

updateOne doesnt update password correctly

In user.model.ts UserSchema.pre('save'...) doesnt get called when using updateOne according to "Pre and post save() hooks are not executed on update(), findOneAndUpdate(), etc. " on https://mongoosejs.com/docs/middleware.html#order.

So a small fix:

UserSchema.pre('updateOne', async function (next) {
const user = this.getUpdate();
if(user.password) {
user.password = await bcrypt.hash(user.password, bcrypt.genSaltSync());
this.update({}, user).exec()
}
next()
});

Threre will be a better solution using the IUserSchema - but i dont know how to get there from the Query Object 💯

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.