Create Node.js app that is packed with best practices AND strive for simplicity

Overview

Best practices starter


Generate a Node.js app that is packed with best practices AND simplicty in mind. Based on our repo Node.js best practices (77,000 stars)

❣️ Alpha stage: It's a very premature work-in-progress, we're only kicking-off now, please revisit by June 2022 🗓

Discord Discord discussions | Twitter Twitter

What in here for you in one paragraph

Node.js has great frameworks 💚 , they never meant to be production ready - Practica.js bridges this gap. Based on your preferred framework, we generate a small code that demonstrates a full flow, from API to DB, that is packed with good practices. For example, we incude a hardened dockerfile, N-Tier folder structure, great testing templates, and more. This can save a great deal of time and painful mistakes. All our decisions are being made, thoughtfully and neatly documented, we strive to keep things as simple and standard as possible and base our work on the popular guide 'Node.js best practices'


Table of contents

A very quick start

🗓 Alpha project: This project is very premature WIP, please revisit by June 2022

Run this command from terminal (not working yet, but it should by April 5th. Please watch)

Interactive mode with UI:

npx @practica/generate interactive

Or a typical terminal command using flags (without UI):

npx @practica/generate generate

That's it, the code was generated for you

Start the project

npm start

or

npm test

Standard, ah?

Enjoy

60-sec-explainer.mp4

Our philosophy and unique value

1. Best practices on top of known Node.js frameworks

We don't invent new wheels rather use your favorite framework and empower it with more structure and practices. For example, with a single command you get express/fastify based code base with ~100 additional best practices inside

Built on top of known frameworks

2. SIMPLE like Node.js was meant to be

Keeping it simple, flat and based on native Node/JS capabilities is part of this project DNA. We believe that too many abstractions, high-complexity and fancy language features become soon a strategic slowdown for the team. To name a few example, our code flow is flat with almost no level of indirection, although using TypeScript - almost no features are being used besides types, for modularization we simply use... Node.js modules

Built on top of known frameworks

3. Supports many technologies and frameworks

Since it's about good practices and simplicity, there is no need to narrow this code to specific framework or DB. We aim to support the major Node.js frameworks and databases

Built on top of known frameworks

Practices and features

We apply more than 100 practices and optimizations, you can opt-in or out for most of these features using our CLI flags. Following is few examples of features, to learn about the full list of features, please visit here

Feature Explanation Flag Documentation link
Monorepo setup Generates two components (e.g., Microservices) in a single repository with interactions between the two --monorepo, --mr Docs here
Output escaping and sanitizing Clean-out outgoing responses from potential HTML security risks like XSS --output-escape, --oe Docs here
Integration (component) testing Generates full-blown component/integration tests setup including DB --tests, --t Docs here
Unique request ID (Correlation ID) Generates module that creates a unique correlation/request ID for every incoming request. This is available for any other object during the request life-span. Internally it uses Node's built-in AsyncLocalStorage --correlation-id, --coi Docs here
Dockerfile Generates dockerfile that embodies 20> best practices --docker-file, --df Docs here
Strong-schema configuration A configuration module that dynamically load run-time configuration keys and includes a strong schema so it can fail fast Built-in with basic app Docs here

📗 Full features list - 100+ more

The people behind this project

Steering committee

Practica is a community-driven open-source project. It's being led voluntarily by engineers from many companies. On top of this, these companies below which are keen to great engineeting practices chose to let their engineers contribute massively and push this project firmly 💚

Autodesk

A Nasdaq 100 company, world-leader in design software

Cox2m

Leader IoT provider, part of 'Cox Communication', 3rd largest US cable company

Core team

Let's put our pictures here really soon

Partners

These companies are keen for continous improvements and encouraging their engineers to contribute during work hours

Minta

Amazing contributors 💚

Million thanks to these great people who contributed code:


Brian Clark

💻

Raz Luvaton

🖋

Michael Solomon

💻

itainoam

💻

shanizlo

💻

Ron Dahan

💻

AlonK

💻
Comments
  • Unable to run the quickstart as it failed at first run

    Unable to run the quickstart as it failed at first run

    What I do?

    mkdir demo-practica
    cd demo-practica
    git init . # To avoid "Command failed: npx turbo run build" due to missing .git and speedup install
    npx @practica/create-node-app immediate --install-dependencies
    

    It returns the following

    ❣️ Command failed: npx turbo run build
    order-service:build: ERROR: command finished with error: command (services/order-service) npm run build exited (2)
    command (services/order-service) npm run build exited (2)
    
    • Packages in scope: @practica/configuration-provider, @practica/error-handling, @practica/jwt-token-verifier, @practica/logger, @practica/validation, order-service
    • Running build in 6 packages
    @practica/configuration-provider:build: cache miss, executing 8bc8fcc61119b8e7
    @practica/validation:build: cache miss, executing 88eb730c59e11ded
    @practica/jwt-token-verifier:build: cache miss, executing f3ee7b28707cce64
    @practica/jwt-token-verifier:build: 
    @practica/jwt-token-verifier:build: > @practica/[email protected] build
    @practica/jwt-token-verifier:build: > tsc
    @practica/jwt-token-verifier:build: 
    @practica/configuration-provider:build: 
    @practica/configuration-provider:build: > @practica/[email protected] build
    @practica/configuration-provider:build: > tsc
    @practica/configuration-provider:build: 
    @practica/validation:build: 
    @practica/validation:build: > @practica/[email protected] build
    @practica/validation:build: > tsc
    @practica/validation:build: 
    @practica/logger:build: cache miss, executing 910860c0ba87745c
    @practica/logger:build: 
    @practica/logger:build: > @practica/[email protected] build
    @practica/logger:build: > tsc
    @practica/logger:build: 
    @practica/error-handling:build: cache miss, executing f45817537faf2b9a
    @practica/error-handling:build: 
    @practica/error-handling:build: > @practica/[email protected] build
    @practica/error-handling:build: > tsc
    @practica/error-handling:build: 
    order-service:build: cache miss, executing 2e3fe06d10230f3f
    order-service:build: 
    order-service:build: > [email protected] build
    order-service:build: > tsc
    order-service:build: 
    order-service:build: domain/new-order-use-case.ts(43,3): error TS2578: Unused '@ts-expect-error' directive.
    order-service:build: domain/order-schema.ts(1,8): error TS1192: Module '"/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/@practica/validation/index"' has no default export.
    order-service:build: entry-points/api/server.ts(18,5): error TS2578: Unused '@ts-expect-error' directive.
    
     Tasks:    5 successful, 6 total
    Cached:    0 cached, 6 total
      Time:    4m14.391s 
    

    Then, I do

    cd services/order-service/
    npm i
    npm run start:dev
    

    It crashs at it inherits from the issues from the first run

    > [email protected] start:dev
    > PORT=0 PRETTY_PRINT=true nodemon start.ts
    
    [nodemon] 2.0.16
    [nodemon] to restart at any time, enter `rs`
    [nodemon] watching path(s): *.*
    [nodemon] watching extensions: ts,json
    [nodemon] starting `ts-node start.ts`
    /home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:820
        return new TSError(diagnosticText, diagnosticCodes);
               ^
    TSError: ⨯ Unable to compile TypeScript:
    entry-points/api/server.ts:18:5 - error TS2578: Unused '@ts-expect-error' directive.
    
    18     // @ts-expect-error TODO: fix this
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
        at createTSError (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:820:12)
        at reportTSError (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:824:19)
        at getOutput (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:1014:36)
        at Object.compile (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:1322:43)
        at Module.m._compile (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:1454:30)
        at Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
        at Object.require.extensions.<computed> [as .ts] (/home/thomasg/own-projects/demo-practica/default-app-name/services/order-service/node_modules/ts-node/src/index.ts:1458:12)
        at Module.load (node:internal/modules/cjs/loader:981:32)
        at Function.Module._load (node:internal/modules/cjs/loader:822:12)
        at Module.require (node:internal/modules/cjs/loader:1005:19) {
      diagnosticCodes: [ 2578 ]
    }
    [nodemon] app crashed - waiting for file changes before starting...
    

    PS: I'm a TypeScript noob so maybe obvious.

    Update: version of Node = v16.13.0 using nvm on a Ubuntu 18.04 64 bits

    opened by ThomasG77 13
  • [Snyk] Security upgrade sequelize from 6.19.0 to 6.21.2

    [Snyk] Security upgrade sequelize from 6.19.0 to 6.21.2

    This PR was automatically created by Snyk using the credentials of a real user.


    Snyk has created this PR to fix one or more vulnerable packages in the `npm` dependencies of this project.

    merge advice

    Changes included in this PR

    • Changes to the following files to upgrade the vulnerable dependencies to a fixed version:
      • src/code-templates/services/order-service/package.json
      • src/code-templates/services/order-service/package-lock.json

    Vulnerabilities that will be fixed

    With an upgrade:

    Severity | Priority Score (*) | Issue | Breaking Change | Exploit Maturity :-------------------------:|-------------------------|:-------------------------|:-------------------------|:------------------------- high severity | 636/1000
    Why? Recently disclosed, Has a fix available, CVSS 7 | SQL Injection
    SNYK-JS-SEQUELIZE-2959225 | No | No Known Exploit

    (*) Note that the real score may have changed since the PR was raised.

    Commit messages
    Package name: sequelize The new version differs by 11 commits.
    • 7bb60e3 fix: properly escaoe multiple `$` in `fn` args (#14678)
    • 86d35b1 docs: added nest option inside findAll query (#14683)
    • 2f3b924 fix(postgres): use schema set in sequelize config by default (#14665)
    • cbdf73e feat: exports types to support typescript >= 4.5 nodenext module (#14620)
    • a333862 docs(readme): update README to be more like main (#14626)
    • e1a9c28 fix: kill connection on commit/rollback error (#14535)
    • b37df96 feat: support cyclic foreign keys (#14499)
    • e37c572 fix: accept replacements in `ARRAY[]` & followed by `;` (#14518)
    • 6c5f8ec test: disable mysql/mariadb deadlock test (#14514)
    • 87655eb build: fix esdoc (#14513)
    • ccaa399 fix: do not replace `:replacements` inside of strings (#14472)

    See the full diff

    Check the changes in this PR to ensure they won't cause issues with your project.


    Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open fix PRs.

    For more information: 🧐 View latest project report

    🛠 Adjust project settings

    📚 Read more about Snyk's upgrade and patch logic


    Learn how to fix vulnerabilities with free interactive lessons:

    🦉 SQL Injection

    opened by mikicho 10
  • Michael/replace syntax to esm

    Michael/replace syntax to esm

    Phase 1 of https://github.com/practicajs/practica/issues/12

    • Update the syntax
    • Fix types

    Open issue: Some props in interactive-cli.tsx don't exist in the definition files, one of them is wrong, we need to find out which and fix then

    opened by mikicho 10
  • Unable to run quickstart

    Unable to run quickstart

    I followed all the steps but on npm start i got this error:

    npm start                                                                                                                                                              🔮  20:34:21
    
    > [email protected] start
    > PORT=3000 PRETTY_PRINT=false node .dist/start.js
    
    node:internal/modules/cjs/loader:361
          throw err;
          ^
    
    Error: Cannot find module '/Users/admin/evenzero/s4NDb0x/default-app-name/node_modules/@practica/logger/.dist/logger.wrapper.js'. Please verify that the package.json has a valid "main" entry
        at tryPackage (node:internal/modules/cjs/loader:353:19)
        at Function.Module._findPath (node:internal/modules/cjs/loader:566:18)
        at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
        at Function.Module._load (node:internal/modules/cjs/loader:778:27)
        at Module.require (node:internal/modules/cjs/loader:1005:19)
        at require (node:internal/modules/cjs/helpers:102:18)
        at Object.<anonymous> (/Users/admin/evenzero/s4NDb0x/default-app-name/services/order-service/.dist/start.js:3:18)
        at Module._compile (node:internal/modules/cjs/loader:1105:14)
        at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
        at Module.load (node:internal/modules/cjs/loader:981:32) {
      code: 'MODULE_NOT_FOUND',
      path: '/Users/admin/evenzero/s4NDb0x/default-app-name/node_modules/@practica/logger/package.json',
      requestPath: '@practica/logger'
    }
    npm ERR! Lifecycle script `start` failed with error:
    npm ERR! Error: command failed
    npm ERR!   in workspace: [email protected]
    npm ERR!   at location: /Users/admin/evenzero/s4NDb0x/default-app-name/services/order-service
    

    OS: OSX 12.5.1 NODE: 16.15.0

    opened by surajsharma 8
  • Add unique request-id (correlation-id) to every request and log statement

    Add unique request-id (correlation-id) to every request and log statement

    🎯 Goal: - The ops/dev should be able to filter out logs and see all the entries of the same request. To achieve this, a unique correlation-id should be added to every request's log statement

    🤔 Things to consider:

    • The implementation should minimally impact the majority of the code: Probably just an initialization when a request starts, then the logger should try to identify whether some store/context/request-id exists and append to logs
    • The standard mechanism in Node.js to achieve this is AsyncLocalStorage, we may use it directly or choose a library that abstracts it. If choosing a library, we may prefer those who use AsyncLocalStorage under the hood and follow our vendor pick guidelines
    • Outgoing HTTP requests should contain the correlation id so other Microservice can reuse the same id
    • This might have impact on performance - Could be useful to benchmark before and after

    🏎 Quick iteration: There are many optimization and testing that can be done here. Let's start with a quick and simple iteration that contains the basics - Initialize a unique id on request start, ensure it's included in all the log entries of the request

    good first issue example-for-demo more-than-3-hours 
    opened by goldbergyoni 8
  • Refactor: Replace CJS code with ESM for code-generator index.ts

    Refactor: Replace CJS code with ESM for code-generator index.ts

    This is to partially address #12 issue with a small scope for now. I also added the node-notifier package as a dev dependency because while it's listed as an option peer dependency when I ran the tests it caused an error indicating it was required. I hope this is ok but please let me know if there is a more appropriate approach to resolve that.

    opened by clarkio 6
  • Fix images on comparison chart

    Fix images on comparison chart

    Hi, I guess you changed the location of some of your images, just a pr to fix them. got here from https://medium.com/autodesk-tlv/lerna-has-gone-which-monorepo-is-right-for-a-node-js-backend-fc075cad51b0

    opened by danm 5
  • Bug/mermaid dark theme

    Bug/mermaid dark theme

    Added new color variation that fit dark and light theme as well. Design is not my strong side so if you think we need other colors, you are welcome to write the hex code. @goldbergyoni Screen Shot 2022-12-06 at 23 47 16 Screen Shot 2022-12-06 at 23 46 31

    needs-more-info 
    opened by marcosmol204 4
  • Enrich the test reporters with 2 cool and useful tools

    Enrich the test reporters with 2 cool and useful tools

    🎯 Goal: - Boost the developer testing experience with reporters that show useful info: The slowest tests and those that were skipped. This might lead to an action by the viewer

    🤔 More details:

    p.s. Share a picture here of the reports when done?

    good first issue less-than-30-minutes non-blocking 
    opened by goldbergyoni 4
  • Generate the code with a templating library

    Generate the code with a templating library

    🎯 Goal: - Currently we generate code by just copying the code-templates folder. We need to run the code files through a templating library so it can be modified based on the user requests. In the future, this will rich logic (e.g., change web framework, avoid requiring files), for now we wish to start with a small step

    ✅Requirements:

    • Add new CLI flag that we accept: --emit-best-practices (file: ./src/code-generator/cli-entry-point.ts). The code contains sections with 'best practices comments' that highlight good practices in the code. The user might want or avoid these parts in the code (see the file global-setup,. line 22)
    • Choose a templating library like handlebars or other. Ensure to pick a very popular one
    • Wrap these 'Best Practices' parts in the code with a conditional expression that your templating library provide. Example with handlebar
    • Try generating code w/o this flag and ensure the output code is as expected
    • Write tests against this new functionality. Too complex for now? You may defer this task or just ask for advice
    enhancement 
    opened by goldbergyoni 4
  • Feat/prisma - allow to choose ORM, sequelize or prisma

    Feat/prisma - allow to choose ORM, sequelize or prisma

    • --orm flag can be set to prisma or sequelize
    • Code generator is refactored to support various future features
    • Component tests of generator
    • Including one more entity/table to show association/relations - Country table
    • Started to document the ORM decision and blog post (not ready)
    • Repository pattern - the DAL entry point returns and gets POJO
    • Sequelize is now strongly typed
    opened by goldbergyoni 3
  • chore: docker

    chore: docker

    • A dockerfile according to official Turborepo docs
    • Change all internal deps to'*' instead to a specific version
    • Remove all package-lock files, except for root

    This PR doesn't handle production build - dev dependencies stay inside the docker, also source TS code.

    (Also, need to review devDeps for all libraries, I believe some are wrong).

    opened by DanielGluskin 2
  • Lacking type coercion during validation

    Lacking type coercion during validation

    When validating input, it's also the right place to coerce value to their right domain type

    For example, when getting req.body.userId - it's string by default, inside our domain it should be a number

    Ajv supports this: https://ajv.js.org/coercion.html

    bug good first issue 
    opened by goldbergyoni 0
  • Decision: Which ORM should we use?

    Decision: Which ORM should we use?

    Like any other decision, we wish to have a discussion and always compare the various options here

    Which Node.js ORM should use? What important dimension should be evaluated?

    decision 
    opened by goldbergyoni 2
  • Decision: Which base docker image should we use?

    Decision: Which base docker image should we use?

    Like any other decision, we wish to have a discussion and always compare the various options here

    Which Node.js image our Dockerfile should inherit from? What important dimension should be evaluated?

    decision 
    opened by goldbergyoni 1
Owner
null
Create flexible REST endpoints and controllers from Sequelize models in your Express app

Finale Create flexible REST endpoints and controllers from Sequelize models in your Express or Restify app. This project aims to be a Sequelize 4.x an

Tom Juszczyk 181 Oct 18, 2022
Senior Design Project. Water intake tracker. Software for the communication to bottle and app. Software for app and database

WaterMate Senior Design Project. Water intake tracker to provide everyone with an easy to use water tracking system that can be integrated with your f

null 3 Nov 10, 2021
Explore, create and deploy your SQLite databases right from your browser. Quick and easy, no installation required.

SQLighter (under development, alpha code) SQLighter is a database explorer born for SQLite that helps you design and deploy your application database

sqlighter 11 Sep 20, 2022
around nestjs, with prisma and some graphql lib,write less code,create power api

介绍 这是一个 prisma + nestjs + graphql 的集成示例 对于开发者来说,特别是使用 graphql 的时候,只需要写非常少量的代码即可完成数据的各种操作,同时也支持接口透传。 开发&部署 本地开发 npm run start:dev swagger 地址:http://loc

芋头 26 Nov 24, 2022
Allows the DAO to manage Saber pools and for anyone to create new pools without permission

Saber Pools Program Allows the DAO to manage Saber pools and for anyone to create new pools without permission. Setup Instructions Running tests Insta

Saber 7 Sep 4, 2022
It is a Discord bot whose goal is to make it easier for server owners to create a so-called Staff/Mode Application

Application Bot MeCodes Application Bot It is a Discord bot whose goal is to make it easier for server owners to create a so-called administration sub

null 26 Dec 12, 2022
AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.

Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a

Andrey Gershun 6.1k Jan 9, 2023
TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite databases.

TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, MariaDB, PostgreSQL and SQLite datab

MikroORM 5.4k Dec 31, 2022
⚡️ lowdb is a small local JSON database powered by Lodash (supports Node, Electron and the browser)

Lowdb Small JSON database for Node, Electron and the browser. Powered by Lodash. ⚡ db.get('posts') .push({ id: 1, title: 'lowdb is awesome'}) .wri

null 18.9k Dec 30, 2022
Execute one command (or mount one Node.js middleware) and get an instant high-performance GraphQL API for your PostgreSQL database!

PostGraphile Instant lightning-fast GraphQL API backed primarily by your PostgreSQL database. Highly customisable and extensible thanks to incredibly

Graphile 11.7k Jan 4, 2023
A simple Node.js ORM for PostgreSQL, MySQL and SQLite3 built on top of Knex.js

bookshelf.js Bookshelf is a JavaScript ORM for Node.js, built on the Knex SQL query builder. It features both Promise-based and traditional callback i

Bookshelf.js 6.3k Jan 2, 2023
The JavaScript Database, for Node.js, nw.js, electron and the browser

The JavaScript Database Embedded persistent or in memory database for Node.js, nw.js, Electron and browsers, 100% JavaScript, no binary dependency. AP

Louis Chatriot 13.2k Jan 2, 2023
🚀 A robust, performance-focused and full-featured Redis client for Node.js.

A robust, performance-focused and full-featured Redis client for Node.js. Supports Redis >= 2.6.12 and (Node.js >= 6). Completely compatible with Redi

Zihua Li 11.6k Jan 8, 2023
An adapter-based ORM for Node.js with support for mysql, mongo, postgres, mssql (SQL Server), and more

Waterline is a next-generation storage and retrieval engine, and the default ORM used in the Sails framework. It provides a uniform API for accessing

Balderdash 5.4k Jan 4, 2023
A wrapper for abstract-leveldown compliant stores, for Node.js and browsers.

levelup Table of Contents Click to expand levelup Table of Contents Introduction Supported Platforms Usage API Special Notes levelup(db[, options[, ca

Level 4k Jan 9, 2023
Adapter based JavaScript ORM for Node.js and the browser

firenze.js A database agnostic adapter-based object relational mapper (ORM) targetting node.js and the browser. Visit http://firenze.js.org for docume

Fahad Heylaal 130 Jul 14, 2022
Modular Redis connection and PUBSUB subscription manager for node. Easily extendable. Built for performance, powered by ioredis.

RediBox Redis connection and PUBSUB subscription manager for node. Built for performance, powered by ioredis (for now). Maintained by TeamFA. What is

RediBox 83 Dec 15, 2022
Add hic et nunc data into your websites and Node.js scripts

hic et nunc API Guide Build websites and Node.js scripts with hic et nunc data hic et nunc is a decentralized NFT marketplace built on the Tezos block

Ian Petrarca 34 May 3, 2022
A back-end server aplication created using node.js, express and mongodb.

Course Material and FAQ for my Complete Node.js, Express and MongoDB Bootcamp This repo contains starter files and the finished project files for all

Pablo César Jiménez villeda 1 Jan 4, 2022