https://github.com/github0013/my-next-project
https://github.com/github0013/my-next-project
Last synced: over 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/github0013/my-next-project
- Owner: github0013
- Created: 2019-09-28T02:02:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T11:35:33.000Z (over 3 years ago)
- Last Synced: 2025-01-23T05:15:48.097Z (over 1 year ago)
- Language: JavaScript
- Size: 461 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 16
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# [AS OF nextjs 9.0.6] how to use prcess.env VARS on now.sh server
## use static env
If you don't use `.env`, then it works as is.
[Build-time configuration][1]
```js
// next.config.js
module.exports = {
env: {
customKey: "value",
},
}
```
## use dotenv
This works on `yarn dev`, `yarn build && yarn start`, but not on now.sh
```ini
# dotenv
CUSTOM_KEY=1234
```
```js
// next.config.js
module.exports = {
env: {
customKey: process.env.CUSTOM_KEY,
},
}
```
## use dotenv on now.sh
`process.env.CUSTOM_KEY` doesn't work out of the box.
[Adding Secrets][2]
run `now secrets add from-dot-env 'from now secret'`, then add
**now.json**
```json
{
"build": {
"env": {
"CUSTOM_KEY": "@from-dot-env"
}
}
}
```
run `now` and see the secrets shows on the screen.
[1]: https://nextjs.org/docs#build-time-configuration
[2]: https://zeit.co/docs/v2/build-step/#adding-secrets