how to set nodejs command `--max-http-header-size` with `nodemon --exec "babel-node" .` - node.js

I am upgrading my nodejs version from 8 to 10. after upgraded, i can't run my application in any browsers right now. so i've been googled my issue and found out that header size of node 10 has been downsized to 8kb from 80kb. my application header size is over 8kb. so i need to set it with nodejs command --max-http-header-size=80000. but i don't know how to set it up with nodemon and babel-node.
Please help.
here is my nodemon.json
{
"ext": "js jsx ejs json gql css",
"exec": "babel-node"
}
and here is my current package.json:
"develop:server": "BABEL_ENV=server nodemon .",
The Solution i've already tried:
{
"ext": "js jsx ejs json gql css",
"exec": "node --max-http-header-size=80000 ./node_modules/babel-cli/bin/babel-node.js"
}
The right solution is below ( choose one of them ):
{
"ext": "js jsx ejs json gql css",
"exec": "NODE_OPTIONS=--max-http-header-size=80000 babel-node"
}
"develop:server": "NODE_OPTIONS=--max-http-header-size=80000 BABEL_ENV=server nodemon .",

I think node engineers reduced the http-header-size from version 8.16.0. they reduced it to prevent attack like DDOS etc. I had the same problem when i upgraded from node version 8.9.1 to 8.16.0. how i solved the problem was in my package.json, I added --max-http-header-size=80000 flag in start script eg
"scripts": {"start": "node --max-http-header-size=80000 server.js"}
and it worked. but if your header is over 8kb then you have to go back to the previous version until the proper fix comes out.

Related

How to watch ts,js,graphql extensions in ts-node-dev?

I am trying to run the node server by ts-node-dev and restart on any any changes in specific files. It is restarting on any changes made to ts,js files however, it is not restarting on changes to graphql files. Any suggestions?
"scripts": {
"start": "tsnd --transpile-only --rs ./src/microservices/index.ts --watch--extionsions
ts,js,graphql"
}

babel-node doesn't transpile JSX in npm react script for Node version 14

I'm having a big problem with running my npm script using babel-node. This script generates static error pages from react components. With Node versions 10 and 12 it is running successfully, but when I have updated my node version to 14 babel-node seems to stop transpiling JSX. Now I get this error:
<MuiThemeProvider theme={theme}>
^
SyntaxError: Unexpected token '<'
at Loader.moduleStrategy (internal/modules/esm/translators.js:140:18)
at async link (internal/modules/esm/module_job.js:42:21)
My devDependencies in package.json file:
"devDependencies": {
"#babel/node": "^7.14.2",
"#babel/preset-env": "^7.14.2",
"babel-plugin-styled-components": "^1.12.0",
"prettier": "2.3.0"
}
and script in package.json:
"generate-error-pages": "babel-node scripts/generate-error-pages.js"
And this is my .babelrc file:
{
"presets": ["#babel/preset-env", "#babel/react"],
"plugins": [["styled-components", { "ssr": true }]]
}
I can't make it work with Node version 14 like it worked with version 10 and 12.
Creating new repository helped me find the problem. In previous versions of Node I had to add
"type": "module"
in package.json because without it there was an exception caused by using import in JS script. Now I observed that in Node 14 I don't need "type": "module" anymore. This was even the problem of described exception. After deleting this from package.json it is now working also in Node 14.

npm script: browser opened using node, but not using babel

Early days in the development of my first npm script, and struggling somewhat. I'm on Ubuntu LTS with the latest nvm, node, npm and pnpm releases.
Node + npm have been installed using nvm, pnpm installed using npm, and several modules installed locally (i.e. without the -g flag) using pnpm. No sudo was necessary. The resulting package.json:
{
"name": "javascript-development-environment",
"version": "1.0.0",
"description": "JavaScript development environment cobbled together using various online sources",
"scripts": {
"prestart": "./node_modules/.bin/babel buildScripts/startMessage.js",
"start": "./node_modules/.bin/babel buildScripts/srcServer.js"
},
"author": "Laird o' the Windy Waas",
"license": "MIT",
"dependencies": {
"#babel/polyfill": "^7.0.0"
},
"devDependencies": {
"#babel/cli": "^7.1.5",
"#babel/core": "^7.1.6",
"#babel/preset-env": "^7.1.6",
"chalk": "^2.4.1",
"express": "^4.16.4",
"open": "^0.0.5",
"path": "^0.12.7"
}
}
With only Firefox 60.0.1 installed, on doing a 'pnpm start' using node, a browser window is opened "Hello World!" displayed, and terminal control has to be regained using a CTRL-C. -> All ok.
If I substitute in babel using the path as shown above (which results from the same issues described in this post), the buildScripts code is echoed to the terminal, but no browser window opens, and terminal control is released immediately on completion. The npm debugger provides no useful feedback. -> Something not working..
As the "Hello World!" code is traversed correctly using node (and remains unchanged for the babel traversal), it is not the source of the problem.
Here my babel config files:
.babelrc
{
"presets": [
"#babel/preset-env"
]
}
babel.config.js
const presets = [
[
"#babel/env",
{
targets: {
edge: "17",
firefox: "61",
chrome: "67",
safari: "11.1",
opera: "56"
},
useBuiltIns: "usage"
},
],
];
module.exports = { presets };
The problem looks to be that babel is not passing the transpiled code on to nodejs / express. Bound to be something simple, but I'm just going round in circles..
One thing I found myself asking is whether there might be a conflict between the various env presets across .babelrc, babel.config.js and package.json. Successive parking of the .babelrc and babel.config.js files, however, brought no change/advance.
I have also noticed that both (nvms) node and (ubuntus) nodejs are currently installed:
$ which node
/home/<myusername>/.nvm/versions/node/v10.13.0/bin/node
$ which nodejs
/usr/bin/nodejs
However, as everything to do with node and npm was installed using nvm, this shouldn't be a problem.
I could, I suppose, try installing babel globally, but with this widely frowned apon. I'd prefer a solution reflecting 'best practice'.
Thanks for any suggestions.
In earlier years, tutor material suggested babel-node would start npm / node (and hence express) on the user's behalf.
babel-node now no longer seems to be recognised. Attempts at using the babel-node command failed, and simply using node in it's place resulted in the transpiler output being dumped to the terminal.
babel, (in our case) pnpm, and node now have to be explicitly called, the latter referencing the transpiled code. node appears to handle interfacing with express.
After some experiment, therefore, the following changes (in package.json) appear to work fine:
"scripts": {
"prestart": "./node_modules/.bin/babel buildScripts/startMessage.js -d dist",
"build": "./node_modules/.bin/babel buildScripts/srcServer.js -d dist",
"start": "pnpm run build && node dist/startMessage.js && node dist/srcServer.js"
},
These result both in a tidy console output and result in "Hallo World!" being displayed in a freshly opened browser window.
Just hope this is of use to someone else.. ;-)

Node.js applies the changes only after restart

I am very new to server side scripting. And I am using NodeJS. My Problem is that after adding some new features to the app, i.e. after changing the code, these changes will be applied only after restarting the server. Till then NodeJS behaves so as though I hadn't changed anything. So for instance if I add console.log("works") and don't restart the server, then it hasn't any effect.
I am using Nuxt.js, which is actually the Vue.js framework but with additional and very usefull features mainly for server side rendering. I didn't integrate the express.js at the beginning of the project, beacause it wasn't planned to write any server side code. So I am normally exporting express and using it, which is pretty fine for me, since I need just a couple lines of code to use the NodeJS file system.
So, as it is pretty hard to code, if I should restart the server once I changed anything, I want to ask you if there is any solution to this problem.
Use nodemon
step 1 : npm install -g nodemon <- this will install nodemon globaly in your system
step 2 : change your start script within package.json
"scripts": {
"start": "nodemon fileName" <- like this //filename is you root file which starts the app like app.js
}
step 3 : npm start
This is already build in into nuxt. You just need to run it in dev mode, not in production.
E.g. for dev with change monitoring
nuxt
For production without monitoring
nuxt start
So in this particular case the following changes to the "scripts" in package.json have solved my problem.
"scripts": {
"dev": "nodemon --watch api --exec \"nuxt\"",
"start": "nodemon nuxt",
}
The following link could also be usefull to you.
Install nodemmon in your application to allow live update npm -g install nodemon
and add the following codes inside your packages json file :
"main": "app.js",
"scripts": {
"start": "node app"
},
on your command line, just type : start

How do you update Openshift NodeJS Cartridge's Express from 3.x to the latest 4.x?

When Openshift creates a Node.js cartridge it includes a version of Express 3. My app is an Express 4 app and fails to start under the default Openshift setup. Even if my app's package.json has the line "express": ">=4.9.0" in dependencies.
4.9.0 happens to be the version that is embedded in my app's project but is ignored by Openshift when started there. So apparently I need to update Openshift's version to 4. I can confirm that the app works as designed and intended on my local computer.
How do I update Openshift's Express, which is outside the app, from version 3 to 4 ?
I made sure that my /package.json includes something like this under dependencies:
"express": "~4.11.1"
Personally, I retired my /bin/www content by removing that out of /package.json:
...
"scripts": {
"start": "node server.js"
},
"main": "server.js"
}
...and migrated much of /bin/www back into /server.js.
That seemed to be the only way I could get Express4 to work on OpenShift.
/server.js needs a shebang a the top "#!/bin/env node"
/package.json gets the mod above
I've got my Express4 app running now with MongoDB support. Seems to be happy. Pushes/builds/logs success.
Which works for me is:
"main": "./bin/www",
"scripts": {
"start": "node ./bin/www"
}

Resources