Skip to content

Commit 2595fc3

Browse files
committed
Improved the Next.js manual setup
1 parent 8c9963c commit 2595fc3

File tree

1 file changed

+36
-62
lines changed

1 file changed

+36
-62
lines changed

docs/documentation/guides/manual/nextjs.mdx

Lines changed: 36 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@ To begin, install the necessary packages in your Next.js project directory. You
2222
<CodeGroup>
2323

2424
```bash npm
25-
2625
npm i @trigger.dev/sdk @trigger-dev/nextjs
27-
2826
```
2927

3028
```bash pnpm
3129
pnpm install @trigger.dev/sdk @trigger-dev/nextjs
32-
3330
```
3431

3532
```bash yarn
3633
yarn add @trigger.dev/sdk @trigger-dev/nextjs
37-
3834
```
3935

4036
</CodeGroup>
@@ -58,67 +54,31 @@ Create a `.env.local` file at the root of your project and include your Trigger
5854
```bash
5955

6056
TRIGGER_API_KEY=ENTER_YOUR_DEVELOPMENT_API_KEY_HERE
61-
TRIGGER_API_URL=https://cloud.trigger.dev
57+
TRIGGER_API_URL=https://api.trigger.dev # this is only necessary if you are self-hosting
6258

6359
```
6460

6561
Replace `ENTER_YOUR_DEVELOPMENT_API_KEY_HERE` with the actual API key obtained from the previous step.
6662

6763
## Configuring the Trigger Client
6864

69-
To set up the Trigger Client for your project, follow these steps:
70-
71-
1. **Create Configuration File:**
72-
73-
In your project directory, create a configuration file named `trigger.ts` or `trigger.js`, depending on whether your project uses TypeScript (`.ts`) or JavaScript (`.js`).
74-
75-
2. **Choose Directory:**
76-
77-
Depending on your project structure, choose the appropriate directory for the configuration file. If your project uses a `src` directory, create the file within it. Otherwise, create it directly in the project root.
78-
79-
3. **Add Configuration Code:**
65+
Create a file at `<root>/src/trigger.ts` or `<root>/trigger.ts` depending on whether you're using the `src` directory or not. `<root>` represents the root directory of your project.
8066

81-
Open the configuration file you created and add the following code:
67+
Next, add the following code to the file which creates and exports a new `TriggerClient`:
8268

83-
```typescript
84-
// trigger.ts (for TypeScript) or trigger.js (for JavaScript)
69+
```typescript src/trigger.(ts/js)
70+
// trigger.ts (for TypeScript) or trigger.js (for JavaScript)
8571

86-
import { TriggerClient } from "@trigger.dev/sdk";
72+
import { TriggerClient } from "@trigger.dev/sdk";
8773

88-
export const client = new TriggerClient({
89-
id: "my-app",
90-
apiKey: process.env.TRIGGER_API_KEY,
91-
apiUrl: process.env.TRIGGER_API_URL,
92-
});
93-
```
94-
95-
Replace **"my-app"** with an appropriate identifier for your project. The **apiKey** and **apiUrl** are obtained from the environment variables you set earlier.
96-
97-
4. **File Location:**
98-
99-
Depending on your project structure, save the configuration file in the appropriate location:
100-
101-
- If your project uses a **src** directory, save the file within the **src** directory.
102-
- If your project does not use a **src** directory, save the file in the project root.
103-
104-
**Example Directory Structure with src:**
105-
106-
```
107-
project-root/
108-
├── src/
109-
├── trigger.ts
110-
├── other files...
111-
```
112-
113-
**Example Directory Structure without src:**
114-
115-
```
116-
project-root/
117-
├── trigger.ts
118-
├── other files...
119-
```
74+
export const client = new TriggerClient({
75+
id: "my-app",
76+
apiKey: process.env.TRIGGER_API_KEY,
77+
apiUrl: process.env.TRIGGER_API_URL,
78+
});
79+
```
12080

121-
By following these steps, you'll configure the Trigger Client to work with your project, regardless of whether you have a separate **src** directory and whether you're using TypeScript or JavaScript files.
81+
Replace **"my-app"** with an appropriate identifier for your project.
12282

12383
## Creating the API Route
12484

@@ -238,18 +198,31 @@ Your `package.json` file might look something like this:
238198

239199
Replace **"my-app"** with the appropriate identifier you used during the step for creating the Trigger Client.
240200

241-
## Next Steps
201+
## Running
242202

243-
Start your Next.js project locally, and then execute the `dev` CLI command to run Trigger.dev locally. You should run this command every time you want to use Trigger.dev locally.
203+
### Run your Next.js app
244204

245-
![Your first Job](/images/cli-dev.gif)
205+
Run your Next.js app locally, like you normally would. For example:
246206

247-
<Warning>
248-
Make sure your Next.js site is running locally before continuing. You must also leave this `dev`
249-
terminal command running while you develop.
250-
</Warning>
207+
<CodeGroup>
251208

252-
In a **new terminal window or tab** run:
209+
```bash npm
210+
npm run dev
211+
```
212+
213+
```bash pnpm
214+
pnpm run dev
215+
```
216+
217+
```bash yarn
218+
yarn run dev
219+
```
220+
221+
</CodeGroup>
222+
223+
### Run the CLI 'dev' command
224+
225+
In a **_separate terminal window or tab_** run:
253226

254227
<CodeGroup>
255228

@@ -271,9 +244,10 @@ yarn dlx @trigger.dev/cli@latest dev
271244
You can optionally pass the port if you're not running on 3000 by adding
272245
`--port 3001` to the end
273246
</Note>
247+
274248
<Note>
275249
You can optionally pass the hostname if you're not running on localhost by adding
276-
`--hostname <host>`. Example, in case your Next.js is running on 0.0.0.0: `--hostname 0.0.0.0`.
250+
`--hostname <host>`. Example, in case your Remix is running on 0.0.0.0: `--hostname 0.0.0.0`.
277251
</Note>
278252

279253
<Tip>

0 commit comments

Comments
 (0)