First entry Nodejs--Response.Write object times wrong

Source: Internet
Author: User

When learning Nodejs, it is customary to use write () to output results in the browser, but when the output is an object, there is a bit of trouble.

Code

varhttp= require(' http ');http.Createserver(function(Request,Response{    Response.Writehead( $,{"Content-type":"Text/html;charset=utf-8"});    if(Request.URL != '/favicon.ico '){        varObj= {"Aid":"123","CID":"5"};                        //Console.log (obj); Console output {aid: ' 123 ', cid: ' 5 '}        Response.Write(obj);    //Error    }    Response.End();}).Listen(8088);Console.Log(' Done ');

Such a Shingwen is not good for my eyes, but I can see that First argument must be a string or Buffer there is a response.write() problem with the parameters.

I thought about it.document.write()

No problem, is it response.write() more than document.write() sentimental??

Silently changed toresponse.write(JSON.stringify(obj));

You win, I endorse ...

First entry Nodejs--Response.Write object times wrong

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.