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

227
Visualizações
Basic Node JS configuration

I just installed Node JS on my ec2 instance (server) using the following site...http://iconof.com/blog/how-to-install-setup-node-js-on-amazon-aws-ec2-complete-guide/

I followed the instructions and I believe I downloaded it all properly, now I am trying to implement Node, but I do not think I am doing it right. I tried tutorialspoint.com but still cannot get it to work.

Basically I am using AJAX when a button is clicked, which in turn calls my node file...

$('#savePic').click(function(e)
{
$.ajax({
    url: "signupServer.js",
    type:'POST',
    data: new FormData($('#formpic')[0]),
    contentType: false,
    processData: false
}).done(function(){

and my node js file looks like this...

var http = require("http");
var fs = require("fs");

http.createServer(function (request, response) {
    fs.writeFile("var/www/html/uploads/test", "Hey there!", function(err) {
        if(err) {
            return console.log(err);
        }

        console.log("The file was saved!");
}); 

I am not using any of the POST data as referenced in my AJAX, I am simply using AJAX to call the code written in my signupServer.js.

The node js file above simply writes "Hey there!" to a file called test located at /var/www/html/uploads/test, but I cannot get it to work. I don't think anything is happening when the button savePic is clicked. Am I using node wrong here?

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

0

You've got most of the pieces, but went wrong in a couple places.

  1. You need to run the node file as a server.
  2. In your AJAX you call the the URL to hit the node server.

Using AWS(ec2) makes this a little more complicated. Your fist step should be to get a "hello world" node app running(there should be listen function in your Node server code) on AWS and successfuly pull up the app in your browsers. If you are new to AWS, this can take some time to figure out Once you get here, I think you will see how to change your code above.

over 4 years ago · Santiago Trujillo Relatório

0

The file type in fs.writeFile isn't specified, it just says var/www/html/uploads/test but it's supposed to be saying var/www/html/uploads/test.txt (or any other file type of your choice)

If that still doesn't work, you'll need to figure out where the problem is.

  • Run the server.
  • load up the HTML file.
  • Open the Network tab in google chrome dev tools. (Press Ctrl + Shift + J, then click Network)
  • try clicking the button savePic.
  • if you see a request go through, the problem is definitely server side.
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