Hi, I'm Vladislav Dekhanov with a brilliant wife and lovely 10 months baby (yes, she is on this header:-)). I'm happy with my family in the self-isolation period till I would need to code something for any of my pet projects :) My baby loves a lot of attention from me and I'm glad to give me all to her, but the lack of time doesn't give me a chance to do anything with the coding :/ I understand that I don't have any templates for my project and backend services in particular. I know this is not rocket science and I need to think about that early, but I'm telling you how things are, pal.
With this technical stack I created a template with important for each MVP project a common feature. This is a user authentication and authorization module. In this template endpoints for registration (/auth/register) and authentication (/auth/login) functionality are implemented. So you don't need to care about how to create and login users. Authorization logic is based on the JWT token exchange. After login action the user on the client-side will receive a signed JWT token, which will be used to authorize him on another protected endpoints. For this logic I added a guard (This is interceptor of the endpoint in the NestJS) with code for checking jwt token and his expiration state. I hope it would help anyone to don't waste the time in the implementation of the users' module for pet projects again, and again, and again...
So, you decide to try this template and how to start? Click the link to generate your repository on the Github from this template or simply clone it from the Github repository page. When you pull this project on your pc you need to configure the project once. First of all go to
/config/.env.example and rename it to
/config/.env file. Here is your configuration of the project. Let me explain each variable:
- JWT_TOKEN - this is the key for signing your jwt token, strongly recommend to change it to keep your app more secure.
- JWT_TOKEN_EXPIRES_IN - duration of validity jwt token signed by application. 1 hour by default. This means that the user won't be authorized on any jwt guarded route even with a signed token 1 hour later. All supported values you can take at the ms utility
- MONGO_DB_CONNECTION - connection to your MongoDB database. For pet projects I recommend using free MongoDB Atlas.
That's all! Now you just need to open a terminal, go to the project folder, type
npm start and go to
localhost:3000 to see
Hello World! message. It means that everything is ok and you can implement your new awesome product. Happy hacking!
If you like my article don't forget to subscribe me on the twitter :)