question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use in a nodejs app?

See original GitHub issue

Hi 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:closed
  • Created 5 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisguttandincommented, Feb 13, 2019

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.

import { setTimeout } from 'worker-timers';

setTimeout(() => {
    console.log('one second elapsed');
}, 1000);

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:

webpack-cli script.js 

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.

<script type="text/javascript" src="dist/main.js"></script>

I hope this helps.

0reactions
chrisguttandincommented, Feb 18, 2019

Alright, I’m happy to hear that you found a solution.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found