DEV Community

Discussion on: Benchmarking Javascript

Collapse
 
skeletor48 profile image
Mihaly Banfi

I am not sure if it answers your question:

In a node.js environment, you will need npm to be installed on your system but basically, it is preinstalled in node.js. (check the documentation on how npmjs.com/get-npm)

Go to your project folder. You have to initialize your project with the npm init command (use npm init -y to prevent further options). This command will generate a package.json file.

A package.json file: (source:docs.npmjs.com/creating-a-package-...)

  • lists the packages your project depends on
  • specifies versions of a package that your project can use using semantic versioning rules
  • makes your build reproducible, and therefore easier to share with other developers

From now on the only thing whenever you want to install a new library/node package into your project is to use the:
npm i [library name] command

Additional options here:

  • npm i [library name] -g -> this installs the library globally on your system without it the installation will live only inside your project
  • npm i [library name] --save-dev -> this installs the package/library only as a dev dependency

My advice here is to just simply use npm i benchmark command in your project folder
From now on you can use benchmark in every file of your project where you require it like this:
const Benchmark = require('benchmark');