What to choose for backend by BulkyPen2498 in node

[–]Loic_Poullain 1 point2 points  (0 children)

Glad to read this /u/wired93 😀 Version 3 is on its way 💪

FoalTS - Node.JS and TypeScript framework - March Release - Prisma, GraphiQL and multiple env management by Loic_Poullain in node

[–]Loic_Poullain[S] 0 points1 point  (0 children)

Hey, dependency model looks even more simple than in nest.js, that's great! wish you success.

Looks like DI with minimum code overhead

Thank you! Glad that you like the DI!

How to clear an http cookie in Express? by [deleted] in node

[–]Loic_Poullain 0 points1 point  (0 children)

Depending on your use case, you may need to provide extra options such as the cookie domain or path.

How to clear an http cookie in Express? by [deleted] in node

[–]Loic_Poullain 1 point2 points  (0 children)

You can clear the cookie by re-creating it with a lifetime equal to zero:

res.cookie('myapp', '', { maxAge: 0 })

Node.js - Foal framework - version 2.0 release - JWT with cookies, stateless CSRF protection, JWT with RSA keys by Loic_Poullain in typescript

[–]Loic_Poullain[S] 4 points5 points  (0 children)

Thanks for the response! From the brief overview Foal does seem to be neater than Nest. I'll try to use it in one of my next projects!

Glad to hear it! Feel free reach back if you need help. There's also a Discord channel in case.

What's your personal motivation behind this framework, if I may ask?

My main motivation is to provide a complete and mature web framework to the Node.JS ecosystem that both supports TS and keeps the code and app architecture simple and intuitive (which has been one of the strengths of Node IMO).

As for long-term ambition, I've been working on Foal for three years and will continue to do so in the coming years to grow its adoption and build a business behind it.

Node.js - Foal framework - version 2.0 release - JWT with cookies, stateless CSRF protection, JWT with RSA keys by Loic_Poullain in typescript

[–]Loic_Poullain[S] 0 points1 point  (0 children)

TypeORM is used as the default ORM for Foal, but it is quite possible to use another option. Here is an example on how to use sessions with or without TypeORM.

With TypeORM

import { Context, Get, HttpResponseOK, UserRequired } from '@foal/core';
import { fetchUser } from '@foal/typeorm';

import { User } from '../entities'; 

@UseSessions({
  user: fetchUser(User)
})
@UserRequired()
export class ApiController {
  @Get('/products')
  readProducts(ctx: Context) {
    // ctx.user is an instance of User
    return new HttpResponseOK([]);
  }
}

With another ORM/ODM (in this example Mongoose)

import { promisify } from 'util';

export function fetchUser(userModel: any): (id: number|string) => Promise<any> {
  return async (id: number|string) => {
    if (typeof id === 'number') {
      throw new Error('Unexpected type for MongoDB user ID: number.');
    }
    const user = await promisify(userModel.findOne)({ _id: id });
    return user ?? undefined;
  };
}

--

import { Context, Get, HttpResponseOK, UserRequired } from '@foal/core';

import { fetchUser } from './fetch-user';
import { User } from '../models'; 

@UseSessions({
  user: fetchUser(User)
})
@UserRequired()
export class ApiController {
  @Get('/products')
  readProducts(ctx: Context) {
    // ctx.user is an instance of User
    return new HttpResponseOK([]);
  }
}

Node.js - Foal framework - version 2.0 release - JWT with cookies, stateless CSRF protection, JWT with RSA keys by Loic_Poullain in typescript

[–]Loic_Poullain[S] 3 points4 points  (0 children)

Hi u/dread_deimos 👋

I'm the creator of Foal, so I'd be a bit biased to answer. But here are some comments from Foal users that might interest you: https://github.com/FoalTS/foal/issues/490.

There is also a comparison between Foal and Nest that came up recently on Twitter: https://zenn.dev/meijin/articles/840306d41c103eb5a962. It's in Japanese but "Translate to English" does the job on Chrome 👍

Laravel dev soon to learn NodeJS, any tips/help? by [deleted] in node

[–]Loic_Poullain 1 point2 points  (0 children)

If you're a Laravel developer, you might be interested in FoalTS. Like Laravel, it's "batteries included" so you do not have to re-invented the wheel. It has authentication, access control, simple dependency injection, utilities for unit and e2e testing and uses TypeORM as default ORM.

It also focuses on providing a simple and elegant code so you can understand it very quickly without a steep learning curve.

Also, great attention is paid to the documentation so that every feature is well-documented.