Giter Club home page Giter Club logo

next-threads-example's Introduction

Next.js Threads Example

This is a minimal example of how to use Next.js with Threads.js, using only TypeScript.

How to use

Start a new Next.js project with TypeScript.

My recommendation is to use create-t3-app.

npm create t3-app@latest

Don't use this repo as a template for your Next.js project. It's not a template, it's a minimal example.

Add threads as a dependency.

npm i threads

Add ts-node as a dev dependency.

npm i -D ts-node

Add the following code to tsconfig.json:

{
  "ts-node": {
    "compilerOptions": {
      "module": "CommonJS"
    }
  },
  ... // other options
}

Copy the content of the api folder to your api folder.

Copy the workers folder to your project

Start the development server.

npm run dev

Next, the workers/workers.config.ts file needs to be adjusted according to your project:

This file is only used for improved type-safety. You can use the Worker class directly if you want.

Go to the fibonacci endpoint and check that everything works.

If the error Error: Cannot find module appears, add or remove the string ../ from the code of the class SingleThreadWorker.

Then, do the same for the fibonacciPool endpoint and the class PoolWorker.

Happy Coding!

next-threads-example's People

Contributors

omer-shahar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.