Environments & Security Exercises

Fill in the blanks to complete the code.

1

Access an environment variable in Node.js

const dbUrl = process..('DATABASE_URL');
2

Set NODE_ENV to production in a shell environment

NODE_ENV=production node server.js
3

Hash a password using bcrypt with a salt round of 10

const hash = await bcrypt.(password, );
4

Verify a bcrypt password against a stored hash

const match = await bcrypt.(plainText, storedHash);
5

Sign a JWT with a secret and 1-hour expiry

const token = jwt.(payload, secret, { expiresIn: '' });
6

Set the HTTP header that prevents clickjacking

res.setHeader('', 'DENY');
7

Specify the Docker base image for a Node 20 app

node:20-alpine
8

Expose port 3000 in a Dockerfile

3000
9

Pass an environment variable into a Docker container at run time

docker run DATABASE_URL=$DATABASE_URL myapp
10

Add the .env file to .gitignore to keep secrets out of version control

echo >> .gitignore