17

It is possible to have multiple threads on nodejs? I am using expressjs and multer for image upload. When an image have big size and webpage needs another request to be accomplished, it waits until image get uploaded. It's possible to make image upload use other thread?

5
  • As far as i know, node.js is single threaded. You can't have another thread do some work for you. However you can send another request to the server as the uploading work happens asynchronously and your request will be processed along with uploading function. Commented Sep 14, 2015 at 10:10
  • I am not sure i understood you. Upload image indeed upload asynchronously but in time i start to upload image i can't send other request. P.S. i am using this plugin: ng-file-upload Commented Sep 14, 2015 at 10:16
  • Do you get any error or your next request is lost or next request gets processed only after image is uploaded? Commented Sep 14, 2015 at 10:44
  • it's not lost, there are no errors, it waits until image get uploaded and then make the request. Commented Sep 14, 2015 at 11:23
  • If your application is CPU-bound, you can use Socketnaut (multithreading) or Cluster (multiprocessing) to scale the main module. Socketnaut has an example specific to Express apps. Commented Sep 21, 2023 at 16:56

1 Answer 1

14

Node.js focuses on asynchronous processing. It is capable of accepting an image upload and servicing other requests at the same time. If it is not doing that it is because your code is doing some kind of synchronous processing. There is a cluster module for running the same node.js code across multiple processes (rather than threads); but it is not what you want. You may find it interesting to understand the difference between concurrency and parallelism. That article is focussed on the Go language so you don't get hung up on node.js specifics. You don't need another thread - you need to better understand the way node.js works. Perhaps you could post the relevant parts of your code in another question for more specific feedback.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.