nodejs

Table of Contents

:ID: 3fc023e6-6173-49ac-93b2-2ab15d6c5508

:END:

NodeJS is an open source JavaScript runtime environment, mostly used to build (backend) applications using JavaScript.

Nodejs support for ECMAScript features: https://node.green/

1. Programming Practices

1.1. on Async

https://stackoverflow.com/questions/43431550/async-await-class-constructor

  • using async converts a function to return a promise

2. Dependency Management

pnpm.io
Fast, disk space efficient package manager | pnpm
npm
initial/builtin for Node
yarn
widespread alternative to npm
  • was implemented to solve early problems with npm, but npm resolved those issues quickly and is now deemed on par with yarn1

./node_modules directory contains all dependency packages, managed in packages.json in project directory.

Why should we use pnpm?. pnpm is an alternative package manager… | by Zoltan …

  • npm@2.x used nested tree structure, with multiple copies of same code if multiple modules depend on it
  • npm@>3.x moved to flattened tree structure, which had to be resolved with every new package install/update
  • pnpm uses nested tree structure but groups it via symlinks

3. CommonJS vs ES Modules

  • ESM is modern default for browsers
  • Node uses CommonJS modules by default
  • Nodejs supports ESM since v10
  • Jest test framework has experimental support for ESM

https://blog.logrocket.com/commonjs-vs-es-modules-node-js/

4. Tools

4.1. Build & Bundle

Since 2022 Vite | Next Generation Frontend Tooling is on the rise. Previously widespread Webpack and colleagues are deprecated. Vite is built around ESM, HMR and bundling for production2.

Comparison with others (current generation): Comparisons | Vite

previous generation:

  • webpack
  • parcel
  • rollup
  • browserify

first generation: grunt, gulp, bower

4.2. Test

If building a new Vite-based project, really Vitest | A blazing fast unit test framework powered by Vite should be used. Features: Features | Guide | Vitest Highlights:

  • built-in mocking (tinyspy)
  • rust-like in-source testing
  • Type Testing (via expect-type)
  • jest-compatible APIs + assertations

The other most popular option (as of 2022) would be Jest · 🃏 Delightful JavaScript Testing

5. Backend/REST API frameworks

express.js
probably the most used, well-known
Angular
classic MVC Framework for SPA
  • supports routers, ORM, modules
  • personal opinion: feels a bit like Spring
Nest
TypeScript + MVC

6. Frontend Component Frameworks

6. Frontend Component Frameworks

Comparison of component syntax: https://component-party.dev/

https://prismic.io/blog/nuxt-vs-next-compare

Next
React + TypeScript
Nuxt
Vue + TypeScript
Nest
TypeScript + MVC Framework, similar to Angular
  • default init comes with Jest Unit+e2e Test setup
Svelte
TypeScript for dynamic components

7. Full Stack Engines for PESPA

7. HTML Template

PESPA = Progressively enhanced Single Page Applications

The big contenders as of [2023-04-15 Sat]:

SvelteKit

Introduction • Docs • SvelteKit What is SvelteKit? SvelteKit is a framework for rapidly developing robust, performant web applications using Svelte. If you're coming from React, SvelteKit is similar to Next. If you're coming from Vue, SvelteKit is similar to Nuxt.

Remix

8. HTML Template Engines

Personally I love pug template engine. It's also easy to integrate into Vite via https://www.npmjs.com/package/vite-plugin-pug

Collection of Responsive Frameworks and Component collections: https://awesome-vue.js.org/components-and-libraries/frameworks.html#responsive

8. ORM

Prisma.io looks nice right now (<2023-05-05 Fri>), may be the future. Lets try prisma.io for a new project

Following the official guide:Add Prisma to an existing project that uses a relational database (15 min) | …

VSCode exentsion: prisma.prisma

npm install prisma --save-dev
npx prisma
npx prisma init --datasource-provider sqlite
# apply format, auto-fill relationships between models
npx prisma format
# create migration with name, apply to database (sync if possible)
npx prisma migrate dev --name init

next steps see: SQLite | Prisma&#x27;s Data Guide

10. Tests

Unit + Integration Tests with Jest

e2e Tests with ? cypress ?

Author: fschl

Created: 2023-05-13 Sat 10:26

Validate