A
A
Andrey2022-04-18 13:56:21
Node.js
Andrey, 2022-04-18 13:56:21

Error accessing .env?

There are two files:

1) .env
2) app.js


There is one line in the body of the ".env" file:
PORT=3000

With this syntax, " app.js " does not work on Ubuntu, everything is ok on Windows:

const express = require('express')
const app = express()
require('dotenv').config();
const port = process.env.PORT;
app.use('/', function (request, response) {
  response.send('Главная страница')
})
app.listen(port)


App.js works with this syntax on both Ubuntu and Windows:

const express = require('express')
const app = express()
app.use('/', function (request, response) {
  response.send('Главная страница')
})
app.listen(3000)


I sin on problems in handling and working with .env, but what's the trouble, I can't understand ...
error"502 bad gateway"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DeFaNJI, 2022-04-18
@chelitsy

Try to write the path to the .env file in the config function call
require('dotenv').config({ path: './.env'})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question