Skip to content

Commit 3d68052

Browse files
authored
[docs] document how to manually load .env files in adapter-node (#8020)
closes #7987
1 parent 1000398 commit 3d68052

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

.changeset/gold-phones-clap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-node': patch
3+
---
4+
5+
Update docs with example of loading environment variables

packages/adapter-node/README.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,33 @@ export default {
1717
};
1818
```
1919

20+
## Deploying
21+
22+
You will need the output directory (`build` by default), the project's `package.json`, and the production dependencies in `node_modules` to run the application. Production dependencies can be generated with `npm ci --prod` (you can skip this step if your app doesn't have any dependencies). You can then start your app with
23+
24+
```bash
25+
node build
26+
```
27+
28+
Development dependencies will be bundled into your app using `rollup`. To control whether a given package is bundled or externalised, place it in `devDependencies` or `dependencies` respectively in your `package.json`.
29+
2030
## Environment variables
2131

32+
In `dev` and `preview`, SvelteKit will read environent variables from your `.env` file (or `.env.local`, or `.env.[mode]`, [as determined by Vite](https://vitejs.dev/guide/env-and-mode.html#env-files).)
33+
34+
In production, `.env` files are _not_ automatically loaded. To do so, install `dotenv` in your project...
35+
36+
```bash
37+
npm install dotenv
38+
```
39+
40+
...and invoke it before running the built app:
41+
42+
```diff
43+
-node build
44+
+node -r dotenv/config build
45+
```
46+
2247
### `PORT` and `HOST`
2348

2449
By default, the server will accept connections on `0.0.0.0` using port 3000. These can be customised with the `PORT` and `HOST` environment variables:
@@ -146,16 +171,6 @@ app.listen(3000, () => {
146171
});
147172
```
148173

149-
## Deploying
150-
151-
You will need the output directory (`build` by default), the project's `package.json`, and the production dependencies in `node_modules` to run the application. Production dependencies can be generated with `npm ci --prod` (you can skip this step if your app doesn't have any dependencies). You can then start your app with
152-
153-
```bash
154-
node build
155-
```
156-
157-
Development dependencies will be bundled into your app using `rollup`. To control whether a given package is bundled or externalised, place it in `devDependencies` or `dependencies` respectively in your `package.json`.
158-
159174
## Changelog
160175

161176
[The Changelog for this package is available on GitHub](https://github.com/sveltejs/kit/blob/master/packages/adapter-node/CHANGELOG.md).

0 commit comments

Comments
 (0)