Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9000727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:20:47+00:00 2026-06-16T00:20:47+00:00

I’m just starting with node.js (and with the whole functional callback paradigm) and I’m

  • 0

I’m just starting with node.js (and with the whole functional callback paradigm) and I’m running into a strange issue. Consider the following code:

var http = require("http");
var myPackage = require("./myPackage.js");  //Custom package

http.createServer(function(request, response)
{
    request.on("end", function()
    {
        //This custom package method retrieves the GET params from the URL
        //and then calls the callback with the params object as argument
        myPackage.getUrlParams(request, function(urlParams)
        {
            response.writeHead(200, {"Content-Type": "text/plain"});

            //This works - it shows me the content of the "data" url parameter,
            //so myPackage.getUrlParams works fine
            response.write("data: " + urlParams.data + ".  ");

            //This does not work - the test file is created with the right 
            //extension in the right place (handled by myPackage) but the 
            //content is "undefined"
            myPackage.toFile("test", urlParams.data);

            //This works - so myPackage.toFile seems to be fine
            myPackage.toFile("test", "Hello World");

            //This obviously works fine
            response.end("Done.");
        });
    });
}).listen(8080);

For some reason, I can write a string to a file, but not the content of the url parameter (which is a simple string, no special characters, spaces, etc). Yet, I can write that url parameter to the screen without problem. Further testing (and writing the test results to the file) gave me the following extra information:

  • myPackage.toFile(“test”, typeof urlParams); writes away “object”
  • urlParams is not null or undefined
  • for (var i in urlParams) returns no results, even though the response.write is called first

I thought this would be some kind of asynchronous thing where my function is called too early (whereas response.write is not, even though it’s called earlier), but then I’d expect urlParams to be undefined and not an object.

Can anyone shed some light on this?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:20:48+00:00Added an answer on June 16, 2026 at 12:20 am

    I’m also new to node.js but I think because your data is an object, you could try passing it through util.inspect() to turn it to a string, like:

    var util = require('util');
    
    ...
    
    myPackage.toFile("test", util.inspect(urlParams.data));
    

    Not sure though, give it a try and let us know. Console.log automatically flattens objects to strings, but toFile() maybe does not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.