Node JSPowerShell

NODE JS Routes and PowerShell Parameterization

While working on Microservice development using NODE JS and PowerShell I have got stumped on Parameterization issue. So far I was working with single parameter all went fine and now got a new scenario where I need to work with two parameters with space as well. Interesting right? Yes, I meant the white space in the routes.

Look at this now!

http://localhost:3000/DisplayName/Chendrayan Venkatesan – Which turns out as http://localhost:3000/DisplayName/Chendrayan%20Venkatesan – Expected but didn’t work. Here my display name Chendrayan Venkatesan should be passed in routes as parameter value for PowerShell script

Failing Code – Using child_process module

My assumption was the value of request.params.DisplayName should be “Chendrayan%20Venkatesan” but it wasn’t

console.log(request.params.DisplayName) – Returned “Chendrayan Venkatesan” absolutely fine!

I tried for few hours over internet and didn’t find the solution to meet my need. So, with no wait I used node-powershell which works like charm!

Using node-powershell module

This works! Sample PS code is below!

Parameter as Name Value Pair

How to pass multiple parameters?

It’s that simple! Now  you plan your PowerShell script ! Mine is ugly like shown below

Navigate to http://localhost:3000/3/4 – Returns 7 on your browser.

 

Leave a Reply

Your email address will not be published. Required fields are marked *