Після чого в myApp.js я вписую тільки умову виконання завдання if (process.env.MESSAGE_STYLE === “allCaps”) {
response = “Hello World”.toUpperCase();
} else {
response = “Hello World”;
}
або я її вписую в функцію? app.get(“/json”, function (req, res){
res.json({“message”: “Hello json”})
if (process.env.MESSAGE_STYLE === “allCaps”) {
response = “Hello World”.toUpperCase();
} else {
response = “Hello World”;
}});
Що не так я роблю, дякую! Посилання на ваші проєкти
solution: http://localhost:3000
Інформація про ваш браузер:
Агент користувача: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36
Завдання: Основи Node та Express - Використання .env-файлу
Yes, I understud, but I’m not sure if I did the whole sequence correctly. And yet, or this import is correctly specified require(‘dotenv’).config(); and what is it for?
The instructions also don’t mention the environment variable value of "allCaps". You need to read and follow the instructions on what string to return and what environment variable value to check for. If you don’t use the values the instructions tell you to use, then it is impossible for you to pass this challenge.
I didn’t quite understand, that is “allCaps” , need to add instead “Hello World” (like is in the file .env), and instead of response = “Hello World” - response = “hello world”?
require(‘dotenv’).config();
let express = require(‘express’);
let app = express();
Створіть файл .env в основі каталогу вашого проєкту та збережіть в ньому змінну MESSAGE_STYLE=uppercase.
Then, in the /json GET route handler you created in the last challenge access process.env.MESSAGE_STYLE and transform the response object’s message to uppercase if the variable equals uppercase. Об’єкт відповіді має бути {"message": "Hello json"} або {"message": "HELLO JSON"}, в залежності від значення MESSAGE_STYLE.
Sorry, maybe I am stupid, but not understand nothing.
So, in the file .env , I have variable var MESSAGE_STYLE = uppercase;
Then in the /json GET route handler, I access process.env.MESSAGE_STYLE : app.get(“/json”, function (req, res){ };
Inside which we write the condition: if (process.env.VAR_NAME === ‘uppercase’) {
let response = “Hello World”.toUpperCase();
res.json({“message”: response})
}
else {
res.json({“message”: “Hello World”});
}
})
So the whole code looks like this:
let express = require(‘express’);
let app = express();
app.get(“/json”, function (req, res){
if (process.env.VAR_NAME === ‘uppercase’) {
let response = “Hello World”.toUpperCase();
res.json({“message”: response})
}
else {
res.json({“message”: “Hello World”});
}
})
p.s(in ukrainian for clarification):
не плутайте Linux з Javascript.
У файлах оболонки, якими є .env, ви повинні використовувати синтаксис оболонки shell.
також вам потрібно трасувати свій код.
Додайте такий код до свого js, щоб побачити, чи бачите ви значення змінної оболонки.
І останнє, але найважливіше, використовуйте markdown для написання коду.
Ось як пиcати код в markdown.
3 зворотні галочки.