// Set an environment variable
process.env.API_KEY = 'your-api-key';
// Access and log the environment variable
console.log('API Key:', process.env.API_KEY);Set and Access Environment Variable
javascript
Related Posts
More content you might like
Tutorial
Build a Custom Rate Limiter in Node.js with Redis
You can now:
- Offer different limits for free vs paid users
- Log or monitor usage per user
Apr 04, 2025
Read More Tutorial
javascript css +1
Building a Real-Time Chat Application with WebSockets in Node.js
npm install express socket.ioCreate a file named server.js in your project directory and add the following:
Aug 03, 2024
Read More Code
php
JWT Token Creation and Verification in Node.js using 'jsonwebtoken'
// Import 'jsonwebtoken' module
const jwt = require('jsonwebtoken');
// Secret key for signing and verifying JWT tokens
const secret = 'mysecretkey';
// Create a JWT token with a payload and set expiration to 1 hour
const payload = { user_id: 123, username: 'john_doe' };
const token = jwt.sign(payload, secret, { expiresIn: '1h' });
// Verify a JWT token
try {
const decoded = jwt.verify(token, secret);
console.log(decoded);
} catch (error) {
console.error('Token verification failed.');
}Jan 26, 2024
Read More Code
javascript
Simple HTTP Server in Node.js
// Import 'http' module
const http = require('http');
// Create a simple HTTP server
const server = http.createServer((req, res) => {
res.end('Hello, Node.js!');
});
// Start the server and listen on port 3000
server.listen(3000, () => {
console.log('Server is listening on port 3000');
});Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!