Hapi, good ald logstash: how to prevent crashes? - hapi.js

I have a Hapi installation which uses good as a logging plugin and good-logstash-tcp extension to send logs to logstash.
My current problem is that logstash server may sometimes be unavailable, and that currently causes the whole server to crash with an error like the following:
/.../node_modules/good-logstash-tcp/lib/logstash.js:178
self.emit('error', new Error('Max retries reached, transport in silent mode, OFFLINE'));
^
Error: Max retries reached, transport in silent mode, OFFLINE
at Socket.<anonymous> (/.../node_modules/good-logstash-tcp/lib/logstash.js:178:36)
at emitOne (events.js:96:13)
at Socket.emit (events.js:191:7)
at TCP._handle.close [as _onclose] (net.js:511:12)
Is there an easy way to make Hapi keep on running even if logging fails for some reason?

Use an utility like pm2 or nodemon to automatically restart your Node application after an error.
Example with nodemon:
1) Install it with npm install -g nodemon
2) Run your app with nodemon index.js instead of node index.js or npm start

Related

create-react-app-typescript failed with Proxy Authentication required error while creating app

I am working in corporate premise. I am trying to create react app with typescript but it failed with below error:
D:\learning\reactjs>create-react-app my-app --scripts-version=react-scripts-ts
Creating a new React app in D:\learning\reactjs\my-app.
Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripemphasized textts-ts...
npm ERR! code E407
npm ERR! 407 Proxy Authentication Required: react-scripts-ts#latest
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\kalpanap\AppData\Roaming\npm-cache_logs\2018-02-21T02_33_17_410Z-debug.log
Aborting installation.
*npm install --save --save-exact --loglevel error react react-dom react-**scripts-ts has failed.*
Deleting generated file... package.json
Deleting my-app / from D:\learning\reactjs
Can anyone help to fix this problem?
Even I have updated npm config proxy and https-proxy to office n/w proxy. After this change only I was able to successfully run the npm install command.
How can I create-react-app with passing proxy parameters?
Thanks in advance
Your company's proxy must be not allowing you to access the setup.
Use the following two commands from command-promt
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
In place of "proxy.company.com", use your proxy address that you are using.
You can find your proxy at
IE Browser -> Internet Options -> Connections tab -> LAN Settings.

yeoman generated app crashes on running grunt command

I am getting the following error when I run the grunt command after generating the app using Yeoman generator:
Loading "grunt-karma.js" tasks...ERROR
>> TypeError: Cannot read property 'prototype' of undefined
>> Local Npm module "grunt-node-inspector" not found. Is it installed?
Running "env:dev" (env) task
Running "sass:dist" (sass) task
Running "less:dist" (less) task
Running "jshint:all" (jshint) task
>> 86 files lint free.
Running "csslint:all" (csslint) task
>> 2 files lint free.
Running "mkdir:upload" task
Running "copy:localConfig" (copy) task
Copied 1 file
Running "concurrent:default" (concurrent) task
Loading "grunt-karma.js" tasks...ERROR
>> TypeError: Cannot read property 'prototype' of undefined
Loading "grunt-karma.js" tasks...ERROR
>> TypeError: Cannot read property 'prototype' of undefined
>> Local Npm module "grunt-node-inspector" not found. Is it installed?
>> Local Npm module "grunt-node-inspector" not found. Is it installed?
Running "nodemon:dev" (nodemon) task
Running "watch" task
Waiting...
[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: server.js config/**/*.js
modules/*/server/**/*.js
[nodemon] starting `node --debug server.js`
(node:16253) [DEP0062] DeprecationWarning: `node --debug` and `node --debug-brk` are invalid. Please use `node --inspect` or `node --inspect-brk` instead.
[nodemon] app crashed - waiting for file changes before starting...
I found a similar question(Yeoman grunt could not connect to MongoDB) but I was not able to find the solution to my problem there.
Is that an old version of MEAN.js? I believe grunt was replaced by gulp and also an issue regarding node-inspector was fixed by this pull request.
You should check which version you're using and make the necessary changes.

How to see logs from npm installation?

I am unable to install ionic through npm. Are there any logs that I can check to see what's wrong and if yes, where are they located?
What I see is the waiting stick dancing forever. I've waited for an hour or so but nothing changes.
Append the --loglevel verbose argument to the command you want to run and all logs will be shown on STDERR and saved to npm-debug.log file in the current working directory.
Example usage: npm install ionic --loglevel verbose.
Running the npm commands like this, shows the logs in realtime and saves the logs to the directory its running within.
For permanent solution, just edit the global npm configuration. To do this, run npm config edit command and add loglevel=verbose. Now every npm command will show detailed logs

npm install work but jspm not

I'm working on an Aurlia.io project. Suddenly the jspm stopped working.
If I retry running the command jspm install, I get an error that a different package failed to load.
warn Error on lookup for npm:babel-runtime
Error: connect ECONNREFUSED 151.101.12.162:80
at Object.exports._errnoException (util.js:873:11)
at exports._exceptionWithHostPort (util.js:896:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)
err Error looking up npm:babel-runtime.
Does anyone have an idea?
#Eliav Maman has the answer in his comment:
Problem solved! just go to edit system environment variables and add
to new user variables 1.HTTP_PROXY= your proxy
2.HTTPS_PROXY=your proxy with https
I'm trying to get this question marked as answered.

How should I set _auth in .npmrc when using a Nexus https npm registry proxy?

Context
My .npmrc file seems to be correctly read (checked with npm config ls -l both from command line and from Maven build).
the machine on which npm is run cannot connect directly to the net, it can only connect to a Nexus npm registry url. Therefore, proxy properties proxy and https-proxy are not set.
As access to Nexus is restricted, I have generated an access token from within Nexus.
Nexus security tokens are made from a username and a password which both contain characters such as / which usually have to be "url encoded"
as expected, with this configuration, when running npm install detects no proxy.
Nexus npm registry proxy seems to be correctly set (I can both access json files and download tgz files using a web browser after having connected using the token generated)
If I set registry to http://registry.npmjs.org/ and comment _auth, email, always-auth, strict-ssl properties, and add proxy and https-proxy configuration, npm install works as expected (but I won't be able to do it on target environment)
Content of .npmrc file
; Nexus proxy registry pointing to http://registry.npmjs.org/
registry = https://<host>/nexus/content/repositories/npmjs-registry/
; base64 encoded authentication token
_auth = <see question below>
; required by Nexus
email = <valid email>
; force auth to be used for GET requests
always-auth = true
; we don't want to put certificates in .npmrc
strict-ssl = false
loglevel = silly
Question
How should I generate the _auth property properly in order to have npm install work as expected?
I tried so far
base64Encode(<username>:<password>)
results in npm info retry will retry, error on last attempt: Error: socket hang up
base64Encode(urlencode(<username>:<password>))
results in npm info retry will retry, error on last attempt: Error: This request requires auth credentials. Run `npm login` and repeat the request.
base64Encode(urlencode(<username>):urlencode(<password>))
results in npm info retry will retry, error on last attempt: Error: socket hang up
When getting the socket hang up error I have the following stack trace:
http request GET https://<host>/nexus/content/repositories/npmjs-registry/fsevents
sill fetchPackageMetaData Error: socket hang up
sill fetchPackageMetaData at TLSSocket.onHangUp (_tls_wrap.js:1035:19)
sill fetchPackageMetaData at TLSSocket.g (events.js:260:16)
sill fetchPackageMetaData at emitNone (events.js:72:20)
sill fetchPackageMetaData at TLSSocket.emit (events.js:166:7)
sill fetchPackageMetaData at endReadableNT (_stream_readable.js:905:12)
sill fetchPackageMetaData at doNTCallback2 (node.js:441:9)
sill fetchPackageMetaData at process._tickCallback (node.js:355:17)
sill fetchPackageMetaData error for fsevents#^1.0.0 { [Error: socket hang up] code: 'ECONNRESET' }
WARN install Couldn't install optional dependency: socket hang up
verb install Error: socket hang up
verb install at TLSSocket.onHangUp (_tls_wrap.js:1035:19)
verb install at TLSSocket.g (events.js:260:16)
verb install at emitNone (events.js:72:20)
verb install at TLSSocket.emit (events.js:166:7)
verb install at endReadableNT (_stream_readable.js:905:12)
verb install at doNTCallback2 (node.js:441:9)
verb install at process._tickCallback (node.js:355:17)
When getting the This request requires auth credentials error I have the following stack trace:
npm sill fetchPackageMetaData Error: This request requires auth credentials. Run `npm login` and repeat the request.
npm sill fetchPackageMetaData at CachingRegistryClient.authify (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\authify.js:17:14)
npm sill fetchPackageMetaData at CachingRegistryClient.makeRequest (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:103:17)
npm sill fetchPackageMetaData at <root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:66:17
npm sill fetchPackageMetaData at RetryOperation._fn (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\attempt.js:18:5)
npm sill fetchPackageMetaData at null._onTimeout (<root>\ui\target\node\node_modules\npm\node_modules\retry\lib\retry_operation.js:49:10)
npm sill fetchPackageMetaData at Timer.listOnTimeout (timers.js:92:15)
npm sill fetchPackageMetaData error for fsevents#^1.0.0 [Error: This request requires auth credentials. Run `npm login` and repeat the request.]
npm WARN install Couldn't install optional dependency: This request requires auth credentials. Run `npm login` and repeat the request.
npm verb install Error: This request requires auth credentials. Run `npm login` and repeat the request.
npm verb install at CachingRegistryClient.authify (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\authify.js:17:14)
npm verb install at CachingRegistryClient.makeRequest (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:103:17)
npm verb install at <root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\request.js:66:17
npm verb install at RetryOperation._fn (<root>\ui\target\node\node_modules\npm\node_modules\npm-registry-client\lib\attempt.js:18:5)
npm verb install at null._onTimeout (<root>\ui\target\node\node_modules\npm\node_modules\retry\lib\retry_operation.js:49:10)
npm verb install at Timer.listOnTimeout (timers.js:92:15)
Sources: https://help.sonatype.com/repomanager3/nexus-repository-administration/formats/npm-registry/npm-security
& https://help.sonatype.com/repomanager3/nexus-repository-administration/formats/npm-registry/publishing-npm-packages
Configure registry (its important doing this before configuring the authentication in step 2, because the authentication settings will be based on the registry):
npm config set registry="http://localhost:8081/repository/npm-internal/"
Configure authentication using a line like the following example:
npm config set _auth="$(echo -n 'username:password' | base64)"
Check the current configuration using the following:
npm config ls
Publish your npm package:
npm publish --registry http://localhost:8081/repository/npm-internal/
If you have authorization token you should not use username:password.
I suggest you:
Generate token
Delete your ~/.npmrc or rename it.
Make sure your env settings like $NPM_CONFIG_* are unset.
Verify that email and other settings are unset by using: npm config list
Log into the npm using: npm login --registry=https://nexus.whatever.registry/respository/npm-whatever-group/
Once you are logged - you are logged. The npm should generate a token for it in your ~/.npmrc. It will look like:
//nexus.whatever.registry/respository/npm-whatever-group/:_authToken=NpmToken.YOUR-LOVELY-TOKEN-IN-HEX
You can use that token in your project, CI pipeline, and other ones. Make sure in your project .npmrc there is:
//nexus.whatever.registry/respository/npm-whatever-group/:_authToken=NpmToken.YOUR-LOVELY-TOKEN-IN-HEX
email = <EMAIL_USED_FOR_TOKEN_GENERATION>
always-auth = true
registry = https://nexus.whatever.registry/respository/npm-whatever-group/
If you have problems with authentication/certs:
add env variable (also to your CI/CD pipline)
$NODE_EXTRA_CA_CERTS to point to /home/wherever/is/your/cert.pem
For CI/CD pipelines (like gitlabs or jenikins):
consider replacing actual values from your .npmrc project file with ${RELEVANT_ENV_VARIABLES}. This way you will make them less visible and always self-updating on change of pipline.
Hope this help.
After having looked at registry-client code I found the answer, here it is. I post it as it may help other people:
base64Encode(<username>:<password>)
By the way, there is an URL encoding, but it's authify.js that takes care of it.
The "socket hang up" problem I'm facing is due to the fact that if a proxy is set in Windows configuration, when launching npm from CLI (and not from a Maven build) all ```.npmrc`` proxy settings seem to be ignored while native proxy exclusions (for corporate urls) are ignored by npm. I'll open a ticket to report this weird behavior.
Before you run npm login, please follow the instructions below :
1) Create an ~/.npmrc file with the following contents:
registry=https://example.com/repository/npm-group/
email=username#example.com
always-auth=true
//example.com/repository/npm-group/:_authToken=
2) run `npm login`
# npm login
Username: firstname.lastname
Password:
Email: (this IS public) firstname.lastname#example.com
Logged in as firstname,lastname on https://example.com/repository/npm-group/.
Use the same password you use to login to example.com
I don't know about Nexus, but we use artifactory as an npm repo, and there I can create my auth token by calling base64encode(username:encryptedPassword) with encryptedPassword being the one I get from my personal artifactory profile.
Maybe this helps.
I just wrote a wrapper that stores the credentials in your systems keychain and provides them on the fly. Check out: https://github.com/Xiphe/npm_keychain_auth