Basic Node JS configuration

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

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?

profilepic.png
manpreet 2 years ago

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.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.