Sat, Oct 30, 21, settig up, nodejs js integration, or with github settings
- Thi
- Setting up
- Usage in a Node.js
- Use with js file
- Use it in Github?
- Use a GitHub Actions secret variable in a bash shell
This is a draft, the content is not complete and of poor quality!
Thi
๐ We use dotenv. ๐ For VSCode, use DotENV extension.
Setting up
For a simple nodejs project,
npm init -y
npm i dotenv
# Create .env in this project
# MAKE SURE IGNORE IT IN GIT !!!
Usage in a Node.js
// At the top of the app
require('dotenv').config()
// Use
const db = require('db')
db.connect({
host: process.env.DB_HOST,
username: process.env.DB_USER,
password: process.env.DB_PASS
})
Use with js file
Use with a simple .js
file? Using command line!
node -r dotenv/config your_script.js
# Custom path
node -r dotenv/config your_script.js dotenv_config_path=/custom/path/to/.env
# Single variable
DOTENV_CONFIG_<OPTION>=value node -r dotenv/config your_script.js
Use it in Github?
# In Github Action
https://github.com/dinhanhthi/<your-repo>/settings/secrets/actions
# In Github Codespaces
https://github.com/dinhanhthi/<your-repo>/settings/secrets/codespaces
# In Dependabot
https://github.com/dinhanhthi/<your-repo>/settings/secrets/dependabot
An example of using Github Action (key SECRET_TOKEN
is already defined in /settings/โฆ),
``` bash
Use a GitHub Actions secret variable in a bash shell
- name: Step 2 - GitHub Action if statement (true) env: WHO_TO_TRUST: $ if: env.WHO_TO_TRUST == โTrustNo1โ run: echo โI know what the secret token is!โ
The following wiki, pages and posts are tagged with
Title | Type | Excerpt |
---|---|---|
Nodejs and NPM install on different platforms | post | Sun, Oct 24, 21, install nvm node npm and other packages, covered by Web Development with Node and Express by Ethan Brown |
serverless application with nodejs | post | Thu, Nov 25, 21, three-tier architecture in user interface(presentation), functional process logic(business rules), computer data storage/access |
node api firebase | page | summary. |