Skip to content

Instantly share code, notes, and snippets.

@audrow
Created December 16, 2021 15:24
Show Gist options
  • Save audrow/96db8f3ce54a1ce3691f03837648ee93 to your computer and use it in GitHub Desktop.
Save audrow/96db8f3ce54a1ce3691f03837648ee93 to your computer and use it in GitHub Desktop.
Deno Web Development by Alexandre Portela Notes #book #webdev

Deno Web Development by Alexandre Portela Notes

  • Architecture
    • Create a top level index.ts file for entry point
    • Create a top level deps.ts file for dependencies and use this file to generate a lock file
    • Every data object has its own folder
      • repository folder for in memory or database
      • controller.ts for main operations
      • index.ts for export
        export type MyType = ...
        export interface MyInterface = {
          myfunction: (arg types) => output types
          ...
        }
        
      • types.ts for types needed around the module
    • Create a folder web for the API routes
    • Create a folder config for the file configuration
      • Uses a YAML file in the top level to specify visible config
      • Uses environmental variables to set secret config
  • Code notes
    • Use Pick<Class, "member1" | "member2"> and Omit<Class, "member3"> to create classes that are subsets
  • Lock files: will check a downloaded packages integrity
    • Creating a lock file
      deno cache --lock=lock.json --lock-write src/deps.ts
      
    • Using the lock file
      deno cache --lock=lock.json src/deps.ts
      
    • Add a dependency, reload the cache
      deno cache --lock=lock.json --reload --lock-write src/deps.ts
      
  • Curl
    • Example commands
        curl -X POST -d '{"username": "audrow", "password": "testpw" }' -H 'Content-Type: application/json' http://localhost:8080/api/users/register
      
      curl -X POST -d '{"username": "audrow", "password": "testpw" }' -H 'Content-Type: application/json' http://localhost:8080/api/login
      
  • JSON Web Tokens (JWT) a way of keeping users in by giving them a temporary token to confirm that they are logged in
  • Benchmarking
    • Use the bench command and run it
    • Use high resolution time to make it more accurate
      deno run --allow-hrtime --unstable src/users/utilBenchMarks.ts
      
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment