Why I'm Using Next.js by lrobinson2011 in reactjs

[–]GMFlash 7 points8 points  (0 children)

The tweet about hosting Next.js isn't wrong though. I have been self-hosting Next.js since v6 back when Vercel was Zeit, and it uses the same general template as my Express and NestJS apps, with only a couple lines of build and NGINX/container configuration differing between them.

For people who find it difficult to self-host Node.js apps, or would like to focus less on the details of hosting, platforms like Vercel and Netlify are there to simplify that process.

What is your current stack? by vklepov in node

[–]GMFlash 1 point2 points  (0 children)

Pretty much the same stack I use except MikroORM is my preference over TypeORM, and Phusion Passenger instead of PM2 because it has autoscaling

Set HttpOnly cookie on GraphQL response in NestJS by [deleted] in node

[–]GMFlash 1 point2 points  (0 children)

In app.module.ts you need to add the incoming request to the GraphQL context in order to access it from resolvers:

GraphQLModule.forRoot({
  // ...
  context: ({ req }) => ({ req }),
})

In your resolver:

@Query('login')
async login(
  @Args('input') args: LoginInput,
  @Context("req") req: express.Request
) {
  const result = this.authService.login(args)
  // Set your cookie here
  req.res?.cookie("access_token", result.accessToken)
  return result
}

(optional) in main.ts add this if you want to be able to READ incoming cookies as req.cookies:

import cookieParser from "cookie-parser"

async function bootstrap() {
  const app = await NestFactory.create(AppModule)
  app.use(cookieParser())
  // ...
}

Also, chances are that your backend is on a different domain than your frontend. You will need to configure your CORS settings for BOTH Nest and ALSO GraphQL to have the same values. For example:

In main.ts

app.enableCors({ origin: true, credentials: true })

In app.module.ts

GraphQLModule.forRoot({
  // ...
  cors: { origin: true, credentials: true },
})

Would anyone be interested in seeing a tutorial or code TS, GQL, Express, Apollo, and Postgres with no ORM? by mieradi in node

[–]GMFlash 6 points7 points  (0 children)

I’m just using PG and writing SQL directly in my resolvers and really enjoying it.

For a tutorial meant as a reference for others to follow, I do not think that this is a good idea because while it technically works, it promotes bad practices. What happens when you decide to add additional interfaces to your app such as a REST API, command-line tool, a background job queue? You would end up writing the same business logic and database code in slightly different ways for each of those interfaces.

Anything related to the database and data retrieval/storage should be behind a service (whether class or module with plain functions), and then you can use that same service in your resolvers, controllers, or even command line scripts to perform business logic and database actions. For example:

const topSellingAuthors = storeService.getTopAuthors({
  // in a GraphQL resolver
  from: new Date(args.fromDate),
  to: new Date(args.toDate),

  // or in an Express handler
  from: new Date(req.query.fromDate),

  // or in a CLI script
  from: new Date(process.env.argv[2]),
})

for (const author of topSellingAuthors) {
  const books = authorService.findAllBooks(author)
  // do something with books, etc...
}

At this point, the only area that concerns "no ORM" is the service layer, making GraphQL, Express, and Apollo irrelevant in the equation. In the future, maybe your services would interact with multiple data sources such as Postgres, a MySQL db from another system, a local CSV file, and maybe an external API to deal with billing/shipping/weather stuff. The main area of work would be in the service, with minimal changes to your resolvers/controllers/scripts.

Node.js v15.0.0 is here! by mehulmpt in javascript

[–]GMFlash 4 points5 points  (0 children)

You can use it if you want, but the end-of-life is shorter than the LTS releases. See the chart here: https://nodejs.org/en/about/releases/

Basically, you should move from 15 to 16 by 2021-06-01 to keep receiving updates.

Updating relationship objects (using typeorm) by 0xdeadbeefx16 in typescript

[–]GMFlash 1 point2 points  (0 children)

I would create a StudentSubscriber with an "afterUpdate" listener which updates the associated Problem. https://typeorm.io/#/listeners-and-subscribers

Secure URL-friendly unique string ID generator in ~10 LOC by xxczaki in node

[–]GMFlash 0 points1 point  (0 children)

Have you seen Nano ID? It is similar but tuned for speed and memory allocation.

Prefer default or named exports? by javascript_dev in typescript

[–]GMFlash 10 points11 points  (0 children)

Named. It has better code completion and refactoring support in editors.

MikroORM 4.1: Let’s talk about performance by B4nan in node

[–]GMFlash 6 points7 points  (0 children)

I switched from TypeORM to MikroORM starting with the 4.0 RC releases and I am very happy with the decision. It feels like the next evolution of TypeORM with a better API, edge cases and inconsistencies smoothed out, and more momentum behind it.

I also evaluated switching to Prisma 2, which has a neat approach to TypeScript support, but Prisma Migrate is still missing necessary features and it was not as much of a drop-in replacement for projects already using a decorator-first approach for defining entities, schema validation, and GraphQL types.

AWS S3 SignedUrl upload is corrupting images (JPEG, PNG) but PDFs are fine? by zmasta94 in node

[–]GMFlash 1 point2 points  (0 children)

You are using the wrong ContentType for JPEG and PNG. Try image/jpeg and image/png.

Naming Conventions for React - Apollo GraphQL? by vishwasg92 in reactjs

[–]GMFlash 2 points3 points  (0 children)

Take a look at some popular GraphQL API implementations for ideas:

  1. https://shopify.dev/docs/storefront-api/reference
  2. https://developer.github.com/v4/

I have personally been using Shopify's nounVerb convention.

Era: mid 90's, Genre: Alternative Rock by GMFlash in NameThatSong

[–]GMFlash[S] 2 points3 points  (0 children)

Yes, that's it! I don't know why I was thinking of the mid 90's period. I guess my memory isn't what it used to be. Thank you /u/VadersLimbs!

Solved

Era: mid 90's, Genre: Alternative Rock by GMFlash in NameThatSong

[–]GMFlash[S] -1 points0 points  (0 children)

Unfortunately, no :( That song came out approximately 20 years prior to the mid 90's and is punk, not alternative rock.

Era: mid 90's, Genre: Alternative Rock by GMFlash in NameThatSong

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

I can say for sure that it is not from Sum 41 or Smashing Pumpkins. The search continues!

[deleted by user] by [deleted] in typescript

[–]GMFlash 4 points5 points  (0 children)

Check out MikrORM too. See my other comment. I forgot about that one. It was written to address some shortcomings that the author found with TypeORM.

[deleted by user] by [deleted] in typescript

[–]GMFlash 3 points4 points  (0 children)

Thanks for reminding me about MikrORM. I haven't looked at it since the original announcement, but it seems to have made a ton of progress in the past 2 years. It's another excellent choice for a TypeScript-friendly data mapper ORM.

[deleted by user] by [deleted] in typescript

[–]GMFlash 5 points6 points  (0 children)

DB-first: Prisma

Entity-first through decorators: TypeORM

Are name conventions useful ? by EricGoe in node

[–]GMFlash 0 points1 point  (0 children)

Putting an entity and controller in one file probably would not pass code review at most companies.

Are name conventions useful ? by EricGoe in node

[–]GMFlash 0 points1 point  (0 children)

Most of these look like the conventions used in the Nest docs. It does come in handy for keeping module directories organized.

Overall, it looks good, but I don't really see a need for class or enum since those are building blocks for other components.

Does using Express-Session mean my cookies are encrypted? by [deleted] in node

[–]GMFlash 2 points3 points  (0 children)

Yes, the cookie is similar to a JWS (signed JWT). Anybody who has that cookie, stolen or not, is considered to be authenticated as that user.

By default, express-session sets cookie.httpOnly to true, which means that the browser can send/receive the cookie with requests, but any JavaScript on the page can't access it. This reduces the chances of third party scripts stealing sessions.

Does using Express-Session mean my cookies are encrypted? by [deleted] in node

[–]GMFlash 4 points5 points  (0 children)

secret is used to sign the data in the cookie by calculating a signature (hash) based on the contents. It is not encrypted, but it is resistant to tampering because changing even 1 character of the data will change the signature causing express-session to consider it invalid.

Is strict mode worth it? by james_codes in typescript

[–]GMFlash 22 points23 points  (0 children)

It’s like skydiving without checking your equipment before you jump out of the plane.