Search code examples
node.jswindowscmdconnectionapplet

Send Data from CMD to Node.Js Server


is there a option to send data from cmd to a NodeJs server? We have a logon script for all Computers in my company and I want them to tell my NodeJs applet who is logged on and the name of the device.

Thanks in advance, Patrick


Solution

  • Client side

    You could use curl in cmd like that:

    curl -d "user=%username%&computer=%computername%" -X POST "https://example.com/"
    

    This example will take send the username and computername environment variables through a post request to the server.
    The only problem about this is that usernames with for example spaces in them are not going to be encoded correctly.

    So I would recommend you to send your request through powershell:

    powershell Invoke-WebRequest -Uri 'https://example.com/' -Method POST -Body @{user=$env:username;computer=$env:computername}
    

    Server side

    On the server side you then receive the post parameters 'user' and 'computer' by parsing the requested with the built in 'url' module. Here you can find a nice example.