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

  • Home
  • SEARCH
  • 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 7846363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:33:32+00:00 2026-06-02T17:33:32+00:00

I literally just found out about Node.js today and I’ve done so much reading

  • 0

I literally just found out about Node.js today and I’ve done so much reading that its making my head hurt. I have the node server up and running. I also have a .JS file on the node server that writes to a text file. I would love to see just one variable (name) get passed from my Javascript application to the server running Node.js so that the Log file gets updated. From what I have read AJAX is the best way to do this. Can someone get me going in the right direction with a small code example on how to do this?

Code of File.js on Server Running Node

var fs = require('fs'), str = 'some text';
fs.open('H://log.txt', 'a', 666, function( e, id ) 
{
  fs.write( id, str + ',', null, 'utf8', function(){
  fs.close(id, function(){
  console.log('file is updated');
});

});
});

  • 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-02T17:33:33+00:00Added an answer on June 2, 2026 at 5:33 pm

    This is how I would do what you mentioned:

    Make a quick http server, look at the request variable of any connection, and get the parameters that were passed in, and write that to the file.

    var http = require('http');
    http.createServer(function (req, res) {
        var inputText = req.url.substring(1);
        processInput ( inputText );
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Completed.');
    }).listen(1337, '127.0.0.1');
    

    Edit here: of course, you still need to define what processInput is.

    function processInput ( text )
    {
        // What you had before
        var fs = require('fs');
        fs.open ('H://log.txt', 'a', 666, function (e, id )
        {
            fs.write ( id, text + ',', null, 'utf8', function() {
                fs.close(id, function() {
                   console.log('file is updated');
                }
            }
        });
    }
    

    This way, when you send a request to

    127.0.0.1:1337/write

    it would write the word “write” into the file (if processInput writes the input).

    Another way to process would be with a parameter in the URI. More information on how to do this is found exactly here at the nodejs api.

    Good luck!

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

Sidebar

Related Questions

Today I found out that putting strings in a resource file will cause them
I literally just started learning HTML and I'm making a basic website in Dreamweaver.
If a program has literally just deserialized an object (doesn't really matter how, but
I'm just wondering which method is the most effective if I'm literally just wanting
There are subprojects and allprojects properties, but how can I just literally list the
I'm literally banging my head against a wall here (as in, yes, physically, at
This is literally driving me nuts. I have 2 entities that use NSStrings as
In my career I have seen literally dozens of ways that people choose to
I have a rather large application that has literally a hundred DDLs with Yes
I've just found something very strange in PHP. If I pass in a variable

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.