How to use in a nodejs app?
See original GitHub issueHi chrisguttandin,
I’ve installed the package from npm and am running a nodejs app. I may be wrong but am struggling how I would be able to use worker-timers in my client pages. Does it need a reqiure() function on the client side? can you show me an example?
e.g. should it be using node_module/worker-timers/build/es5/bundle.js in the client page like:
import * as workerTimers from '.libs/bundle.js';
or
<script src=".libs/bundle.js"></script>
Looking forward to your reply. Thanks
Issue Analytics
- State:
- Created 5 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Getting Started Guide - Node.js
Once we have installed Node.js, let's build our first web server. Create a file named app.js containing the following contents: ... Now, run...
Read more >node.js - NodeJS / Express: what is "app.use"? - Stack Overflow
The app.use() function is used to mount the specified middleware function(s) at the path which is being specified. It is mostly used to...
Read more >Build Node.js Apps with Visual Studio Code
The Visual Studio Code editor has great support for writing and debugging Node.js applications. This tutorial takes you from Hello World to a...
Read more >Express.js | app.use() Function - GeeksforGeeks
The app.use() function is used to mount the specified middleware function(s) at the path which is being specified.
Read more >Node.js - First Application - Tutorialspoint
Creating Node.js Application · Step 1 - Import Required Module · Step 2 - Create Server · Step 3 - Testing Request &...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @ctlkkc, sorry for the confusion. The naming is a bit misleading. It’s definitely true that naming is one of the hardest problems in software development. 😃 The file bundle.js is not a bundle which can be loaded with a script tag. It’s called bundle because it bundles all source files, but it does NOT bundle any dependencies. In other words you need to create a bundle which contains your code, worker-timers and it’s dependencies. Here is a simplified example how you could do that with webpack. But any other bundler should work as well.
Create a file with your code which imports worker-timers. Let’s call it
script.js
.Now you can use the webpack-cli with
script.js
as the entry point. webpack will look up all dependencies and create a single combined file. Just run the following command in your working directory:You can of course provide an extensive configuration but it should also work without any configuration at all. By default webpack will save the bundle as
dist/main.js
. This is the bundle which you can reference with a script tag.I hope this helps.
Alright, I’m happy to hear that you found a solution.