weixin_33720452 2016-02-15 02:02 采纳率: 0%
浏览 40

基本Node JS配置

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?

  • 写回答

2条回答 默认 最新

  • 7*4 2016-02-15 03:26
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加