could someone tell me how to stop storing data into mongoDB in Test environment in nodejs via process environment variable. just want to run the node app like follow
ex: test dbConnection = false node index.js
many thanks for any help
Related
I'm trying to hack my own node app and extract secrets from it by attaching a debugger to the running process. It's a NestJS / Express app.
So there is a compiled main.ts file of the same form as here running.
I am attaching a debugger via node inspect -p $PID. I can now go into a repl, but from there I don't know how to access the instantiated NestJS objects...
There is a ConfigService class from which I would like to retrieve the variables.
How would I continue here?
I am developing sample apps and would like to know process.env variables,
I know console.log(process.env) will return its variables.
But can I see them after run its server ?
npm start
I couldn't input anything in console.
As I am new to node.js, will you please let me know.
by switing NODE_ENV, it seems that development,staging,production is switched.
So that I would like to comfirm them.
Thanks
If you start your server in docker and don't pass custom variables to process.env in your app, you can see your env by docker command:
docker exec your_container env
Yet another way - create a specific route in your application that will be return you all data from process.env.
Something like this:
GET yourserver/api/system/env
But this way is not secured and you should think about protection of your system route.
UPD
Also you can call console.log(process.env) after server has been started.
await app.listen(3000);
console.log(process.env);
I'm using console.log for debugging some information in my web app using node.js, expressjs and PM2. All is working fine :)
I want to know if my web app can have performance problems in production if I use console.log this:
var myVariable = "Enter in this section of code";
console.log(myVariable);
I have read about console.log is synchronous and can affect to my performance... if this is real in this moment (I'm using Express 4), how can I remove these console.log in different environments like production?
I'm using PM2 (pm2 logs command) to watch the logs and pm2 flush to clean the logs.
Thanks.
You could use winston for logging , you could configure transport depending on your env , for example you could use Console and File tranports in development and just File in production. PD: pm2 takes data from std log(console)
I installed mongo on my elastic beanstalk node.js app and started the mongo daemon process. I'm not quite sure how to connect to the database though. On my local node app, I'm able to connect with these credentials:
module.exports = {
'url' : 'mongodb://127.0.0.1:27017/test'
}
I'm assuming that it doesn't connect because I need a user, password, and to create a database to connect to, but I'm not sure how to go about doing that on the remote database. I'm also finding resources on setting mongo up on t1.micro to be very scarce, so there's not much help there.
I didn't realize that I had to start up the mongo processes myself. Run mongod.
I am building a web app in Node.js, Express, and MongoDB using Mongoose. I want to have a dedicated database for when i run my Mocha tests with Grunt so that I do not mess up the database I am using for development. How would I do this?
I currently have my development database configuration information in a file at /config/db.js, which is loaded and connecting to my development database in my app.js file at startup. How would I make my Mocha tests, that are run in a Grunt task, use a test database dynamically when I run Grunt? I have tried to disconnect from development database in my test files in the before() hook in my Mocha test files, and then connect to test database. However, it keeps using development database. An example is the following:
before(function(done) {
if(mongoose.connection.db) mongoose.connection.close();
mongoose.connect(<test_db_uri>, done);
}
Your question is near of the following question Test environment in Node.js / Express application.
Basicly what you should do is use an env variable ('NODE_ENV' for exemple) access it with process.env.NODE_ENV and base on its value call the right configuration file. You should take a look to grunt-express-server which helps you a lot with the environement setup.
I hop this will help!