Skip to content

Omer-Shahar/next-threads-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A minimal example of how to use Next.js with Threads.js, using TypeScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published