Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

292
Visualizações
How can i successfully create a simple form using nodejs without external modules

So i've been working on this for a bit:

/*
API 1 Docs: https://docs.genius.com/#/getting-started-h1
API 2 Docs: https://pastebin.com/doc_api
*/

let https = require('https')
//const qs = require('querystring');


function handler(req, res){
  if(req.method == "GET"){ 
    res.setHeader('Content-Type', 'text/html');
    res.writeHead(200);
    res.end("<html><body><form action='/' method='post'><input type='text' name='hello'><input type='submit'></form></body></html>");
  } else if(req.method == 'POST'){
    res.setHeader('Content-Type', 'text/html');
    res.writeHead(200);
    res.end(`<html>Success Posting!</html>`)
    /*
    var body;
    req.on('data', function(data) {
      body += data;
      if (body.length > 1e6) {
        // FLOOD ATTACK OR FAULTY CLIENT, NUKE REQUEST
        req.connection.destroy();
      }
    });
    req.on('end', function() {
      var POST = qs.parse(body);
      let data = POST.submit
      res.end(`<html>${data}</html>`)
    });
    */
  } else {
    res.writeHead(200);
    res.end();
  };
};


https.createServer(handler).listen(3000, function(err) {
  if (err) {
    console.log('Error starting https server');
  } else {
    console.log('Server listening on port 3000');
  };
});

(Please ignore commented code) I had it working before and all of a sudden, it stopped working, it created a form and upon submitting it it would change the page to "Success Posting" but now all of a sudden its not and ive been making small changes not knowing my problem

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It appears that I need to create an http server using the http module instead of making an https server with the https module

Before:

const https = require('https')

https.createServer(handler).listen(3000, function(err) {
  if (err) {
    console.log('Error starting https server');
  } else {
    console.log('Server listening on port 3000');
  };
});

After:

const http = require('http')

http.createServer(handler).listen(3000, function(err) {
  if (err) {
    console.log('Error starting http server');
  } else {
    console.log('Server listening on port 3000');
  };
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda