Passing variable from html form to nodejs


I am creating a webproxy with nodejs to be able to access "anonymously" to another site, so this is my server:

const http = require("http");
const url = require("url");
const request = require("request");
const fs = require('fs')
var server = http.createServer(onRequest);

function onRequest(req, res) {
  var queryData = url.parse(req.url, true).query;
  if (queryData.url) {
    request({ url: queryData.url })
      .on("error", function(e) {
  } else {
    fs.readFile("index.html", (err, html) => {
      if (err) {
      }else {



Fortunately, my eyesight loads:

<!DOCTYPE html>
<html lang="en" dir="ltr">
    <meta charset="utf-8">
    <div class="container mt-5">
      <div class="row mt-5">
        <div class="mx-auto mt-5">
          <div class="form-group">
            <form class="" method="post">
              <input type="text" class="form-control" id="url" placeholder="">

Even the proxy works for me, since I would only have to add the url of the page I want to visit to the variable called url in the header as follows: link and go, get it right. What I want to do is a kind of get request for the url variable to access the input value of the form, but I do not have the slightest idea. Does anyone have any ideas?

asked by Diesan Romero 23.08.2018 в 02:58

1 answer


Try this:

<form action="" method="get">
  <input type="text" class="form-control" name="url" placeholder="">
  <button type="submit">Enviar</button>

Notice the property action and method of <form> . With action we tell you what url to make the request and with method how to do it, in this case get .

Now in the input we put the names of the values that we want to send with the property name (in this case url ).

answered by 23.08.2018 / 05:06