How to set log level in Winston/Node.js

If you are using the default logger, you can adjust the log levels like this: const winston = require(‘winston’); // … winston.level=”debug”; will set the log level to ‘debug’. (Tested with winston 0.7.3, default logger is still around in 3.2.1). However, the documentation recommends creating a new logger with the appropriate log levels and then … Read more

Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

This seems to work: gulp.src([ baseDir + ‘/**’, // Include all ‘!’ + baseDir + ‘/excl1{,/**}’, // Exclude excl1 dir ‘!’ + baseDir + ‘/excl2/**/!(.gitignore)’, // Exclude excl2 dir, except .gitignore ], { dot: true }); Excluding single file from glob match was tricky because there’s no similar examples in minimatch docs. https://github.com/isaacs/minimatch “If the … Read more

MongooseJS – How to find the element with the maximum value?

Member .findOne({ country_id: 10 }) .sort(‘-score’) // give me the max .exec(function (err, member) { // your callback code }); Check the mongoose docs for querying, they are pretty good. If you dont’t want to write the same code again you could also add a static method to your Member model like this: memberSchema.statics.findMax = … Read more

How to fix AXIOS_INSTANCE_TOKEN at index [0] is available in the Module context

Import HttpModule from @nestjs/common in TimeModule and add it to the imports array. Remove HttpService from the providers array in TimeModule. You can directly import it in the TimeService. import { HttpModule } from ‘@nestjs/common’; … @Module({ imports: [TerminalModule, HttpModule], providers: [TimeService], … }) TimeService: import { HttpService } from ‘@nestjs/common’; If your response type … Read more

Node script throws uv_signal_start EINVAL

The error isn’t with node-dev, but rather in your script. Error: uv_signal_start EINVAL is thrown in newer versions of node when you’re trying to work with SIGKILL or SIGSTOP, like so: process.on(‘SIGKILL’, function() { // etc, etc You probably got away with this in earlier versions, but newer versions will now throw this error (see … Read more

Node.js – How to get my external IP address in node.js app?

Can do the same as what they do in Python to get external IP, connect to some website and get your details from the socket connection: const net = require(‘net’); const client = net.connect({port: 80, host:”google.com”}, () => { console.log(‘MyIP=’+client.localAddress); console.log(‘MyPORT=’+client.localPort); }); *Unfortunately cannot find the original Python Example anymore as reference.. Update 2019: Using … Read more