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 8040891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:02:29+00:00 2026-06-05T04:02:29+00:00

In my express server there are some functions which I need to run as

  • 0

In my express server there are some functions which I need to run as child processes because otherwise they’ll tie up the server and other people won’t be able to access it. They’re already using the async module but they still tie up the server unless they’re run as child processes.

One problem is passing the req and res parameters to them.

How can this be done?

  • 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-05T04:02:30+00:00Added an answer on June 5, 2026 at 4:02 am

    Using child_process.fork, you can send messages to child processes.

    Edit: I incorrectly advised to pass req and res as message parameters to the child process. This is not possible, as all messages to and from child processes are converted to JSON. Instead, you could keep some kind of queue in your server. The below is only meant as an example, you may want something more robust:

    child.js:

    process.on('message', function(message) {
        // Process data
    
        process.send({id: message.id, data: 'some result'});
    });
    

    server.js:

    var child_process = require('child_process');
    var child = child_process.fork(__dirname + '/child.js');
    var taskId = 0;
    var tasks = {};
    
    function addTask(data, callback) {
        var id = taskId++;
    
        child.send({id: id, data: data});
    
        tasks[id] = callback;
    };
    
    child.on('message', function(message) {
        // Look up the callback bound to this id and invoke it with the result
        tasks[message.id](message.data);
    });
    
    app.post('/foo', function(req, res) {
        addTask('some data', function(result) {
            res.send(result);
        });
    });
    

    It’s a bit more involved, but it should work. You may quickly grow out of such a system, and may be better served by a proper queue.

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

Sidebar

Related Questions

I am looking for options other than MS SQL Server/Express. There seem to be
just wondering: is there some kind of 'Express' edition of Windows Server 2008 that
Initiation I have a SQL Server Express 2008 R2 running. There are ten users
i'm trying to set up some tables in my SQL Express server, and i
SQL Server Express does not have the Tasks -> Import Data option that other
i already had 2008 express sql server but for some reason it came without
HI ALL, I am using sql server express to store some data but it
I've got a SQL Server Express 2008 install on my web server, which by
I can't seem to figure out how to get my express server to run
I'm having some trouble with a SQL Server 2008 R2 (Express) installation. It seems

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.