Posts

NodeJS modules shrink

Image
I'm a newbie in NodeJS and I'm not really familiar with all this thing of "npm". I mean, I didn't expect that just for one "npm install" I will get 10Mb of 30 different folders.  After a bunch of minutes when I processed this fact, I just realize that there are a lot of junk in those folders. They are not "compiled", let's call it this way... There are "readme" files, source files, test scripts, example applications, docs and so on!!! Many of modules has duplications of another modules inside their folders. Like “inherits”, “core-util-is”, “tedious” etc. Modules inside modules, Karl! And inside them – another modules, that already exist in other modules in the project. Whaaaaat???!!! There is an example of one of them - I'm in "node_modules" and in "bl" folder, but there is another "node_modules" folder inside it as well as "test", "readme" and all this junk here. And all of

NodeJS and npm: [npm ERR! cb.apply is not a function]

Image
Lately I ran over this issue and I want to share with you how I got out of there:  C:\>npm i npm -g npm WARN npm npm does not support Node.js v14.17.0 npm WARN  npm  You should probably upgrade to a newer version of node as we npm WARN  npm  can't make any promises that npm will work with this version. npm WARN  npm  Supported releases of Node.js are the latest release of 6, 8, 9, 10, 11. npm WARN  npm  You can find the latest version at https://nodejs.org/ npm ERR! cb.apply is not a function npm ERR! A complete log of this run can be found in: npm ERR!       %USERPROFILE% \AppData\Roaming\npm-cache\_logs\2021-05-30T14_58_58_367Z-debug.log  It was after I installed a latest version of NodeJS. Command  npm -v returned something like 6.*.* We've tried to reinstall NodeJS. We've tried to remove %USERPROFILE%\AppData\Roaming\npm-cache . We've tried to uninstall NodeJS (together with npm). We've tried to install NodeJS again. We've tried to reinstall graceful-f

AWS API Gateway with Lambda: add "Get By ID" definition

Image
This thing is not trivial and I didn't found any simple explanation about this. So that is  select an existing resource (eg. "users") click on "Actions" dropdown and select "Create Resource" in " Resource Name " put parameter name in curly braces (eg. {userid}) in " Resource Path " you should see read-only text " /users/ " and textbox for parameter write {userid} in this textbox and click " Create Resource " you should see a new branch in your API tree - /{userid} . Select it. click  "Create Resource"-"Create Method" and add ANY method there integrate it with Lambda function you alrteady used for ANY of this resource (don't forget check " Use Lambda Proxy integration ") select this new brand ANY method, go to "Method Request" and ensure that there is "userid" parameter in "Request Paths" section That is it. Now you should handle it in your Lambda (to

DB backup under SQL Express

SQL Express has no Jobs engine. And Shared SQL server as well. So Management->Maintenance Plans is not exists. So there is a batch file that you can put in Windows Scheduler to create db backups: @echo off set databaseName=%1 echo %databaseName% set backupFolder=%2 echo %backupFolder% for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a" set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%" set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%" set "fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%" echo %fullstamp% set OutDir=%backupFolder%\%databaseName%_%fullstamp%.bak echo %OutDir% sqlcmd -S <serverName\instanceName> -U <user> -P <pass> -Q "BACKUP DATABASE [%databaseName%] TO disk='%OutDir%'" References :  Filename timestamp

Decimal number issue from server to client. Wow! Didn't expect this @_@

Image
Chapter 17   where poor Decimal Number came from Server Side to JavaScript I worked on some page for days to adjust UI by CSS and HTML changes. It was pretty OK and fine. Until I started to check this page for multi-lingual support... It was good for English, Spanish and Chinese. And even right-to-left Hebrew! Crooked and askew but working! But not in Russian, no! In Russian it stopped working at all - nothing except static texts and images wasn't appeared. And of course it was an error in JS :-\ (FireFox DevTools): that led me strangely to somewhere to this code: I was staring on this rows and saw nothing wrong there - no missing variables at all. I went to original code in the project to discover the non-rendered rows and saw server variable there: that led me to server side C#: Nothing wrong at all. Here and there - another 10-15 minutes wasted to dumbly running the page again and again and stupidly staring on all these rows in different windows... :-\ Sad... Un

Configuring IIS to allow CORS requests

Image
The problem:   sending ajax requests from HTML5 application on local machine to my API that hosted under IIS on Google Cloud. The facts:  The code looks like:         $.post({             url: apiEndpoint + "Init",             contentType: "application/json; charset=utf-8",             data: data,             success: function (response) {                 logResponse("API response [Init]", response.d);             },             error: function (xhr, status, error) {                 logResponse('Fail to call init API', data);             }         }); The error was looks like: Originally, there was "crossDomain: true" parameter in ajax request but it doesn't help. There were crossdomain.xml and clientaccesspolicy.xml on the server and they were helpless as well. The way: I went to internet for advice and saw many and many solutions for ajax - nothing doesn't help. What I tried: - add to ajax   

TRIM unwanted chars from string in SQL

It's pretty simple but I didn't know this: TRIM ( '.,! ' FROM '# test .' )