I'm beginner with Nodejs, so, i'm sorry if I did some wrong, and tell me how to solve, please...
In my case, I put all credentials inside .env
file and my index.ejs
try extract the data, but, I see error "require is not defined
" because I try use 'dotenv
' here, see my example (.ejs).
In the case, 'dotenv' is a module too extract values inside .env
file and this work for give security to the values
of the variables
.
If it does not have like, I would like to know what I could do to solved the problem, remembering that it is for security of credentials.
My new EJS file:
<html>
<head>
<script src="jquery-3.1.1.js"></script>
<script src="app.js"></script>
<base href="/">
<title>XXXXXXXXXXXXXXXX</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta property="og:image" content="XXXXXXXXXXXXXXXX.svg" />
<meta property="og:title" content="XXXXXXXXXXXXXXXXXXSimple" />
<meta property="og:description" content="My description" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="css/app.css">
</head>
<body>
<div id="view-change-button" class="button" onclick="Payloadxxxxxxx.togglePanel(event, this)">
<img class="option full" src="../img/Chat Button.png">
<img class="option not-full" src="../img/Code Button.png">
</div>
<div id="contentParent" class="responsive-columns-wrapper">
<div id="chat-column-holder" class="responsive-column content-column">
<div class="chat-column">
<div id="scrollingChat"></div>
<label for="textInput" class="inputOutline">
<input id="textInput" class="input responsive-column"
placeholder="Digite algo" type="text"
onkeydown="xxxxxxxxxxxxxxxxPanel.inputKeyDown(event, this)">
</label>
</div>
</div>
<div id="payload-column" class="fixed-column content-column">
<div id="payload-initial-message">
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxOtherDescription.
</div>
<div id="payload-request" class="payload"></div>
<div id="payload-response" class="payload"></div>
</div>
</div>
<script>
var lgn = <%- JSON.stringify(lgn) %>; //solution by @Jak
var pas = <%- JSON.stringify(pas) %>; //but show the values in console
// var lgn = process.env.LOGIN;
// var pas = process.env.PASS;
var numberOrigin = 330;
function test(){
var obj2 = login(lgn, pas, numberOrigin);
numberOrigin++;
}
var obj;
function xxxx(xxxxxxxxxxxxxxxxxxxx){
numberOrigin +=1;
//some codes with ajax
function otherFunction(){
//otherFunction code
}
</script>
// I need the .js files for my function to work fine
<script src="js/xxxxx.js"></script>
<script src="js/xxxxxxxx.js"></script>
<script src="js/xxxxxxxxxx.js"></script>
<script src="js/xxxxxxxxxx.js"></script>
<script src="js/xxxxxxxxx.js"></script>
</body>
</html>
Obs.: My app.js works fine with require( 'dotenv' ).config( {silent: true} );
, (.env
file with credentials for other API), but the file is .js
and not .ejs
.
I'm not sure if dotenv
works with EJS
, but, if not, someone can help me how to ensure that my credentials will not be seen?
EDIT:
After try with the possible solution By @Jak Hammond, my code index.ejs
:
My code inside Console Chrome (It's possible see the credentials):