NodeSand is a powerful CLI utility tool that provides various tools for experimenting with simple code or benchmarking in a Node.js environment.
Tue Jan 31 2023 09:03:30 GMT+0900 (Korean Standard Time)
==================================================
β Main function is running...
Hello, World!
β Done!
==================================================
50.02708297967911 ms- Serve static HTML file
- Code benchmarking
- TypeScript support
- ESLint & Prettier support
- Observation mode
- Execution time report
We recommend using Node.js version 20 or higher to use NodeSand.
$ npm init nodesandBefore you begin, you need to install the dependent packages.
$ npm i
# or...
$ pnpm iSource files of node scripts (dev, once, watch) are located in src/node/index.js. When all the actions are done, we call next() to end execution.
Run the script at once with the following command:
$ npm run once
or
$ npm run devRun whenever the script file changes with the following command:
$ npm run watchYou can run benchmarks using various code comparison sets in Node.js. (We use Tinybench for benchmarking.)
Write the code in src/bench/index.js as follows:
export const benchConfiguration = { name: 'Benchmark', time: 100 };
export default function defineBenchmarks(bench) {
bench
.add('faster task', () => {
console.log('I am faster');
})
.add('slower task', async () => {
await new Promise((resolve) => setTimeout(resolve, 1)); // we wait 1ms :)
console.log('I am slower');
});
}Then simply run the following command:
$ npm run benchThen the benchmarking results will be displayed as shown in the example below.
β Done!
===========================================
Benchmark:
791.840458 ms
βββββββββββ¬ββββββββββββββββ¬ββββββββββββββββββββ¬βββββββββββββββββββββ¬βββββββββββββββββββββββββ¬βββββββββββββββββββββββββ¬ββββββββββ
β (index) β Task name β Latency avg (ns) β Latency med (ns) β Throughput avg (ops/s) β Throughput med (ops/s) β Samples β
βββββββββββΌββββββββββββββββΌββββββββββββββββββββΌβββββββββββββββββββββΌβββββββββββββββββββββββββΌβββββββββββββββββββββββββΌββββββββββ€
β 0 β 'faster task' β '3861.8 Β± 2.74%' β '3500.0 Β± 166.00' β '277861 Β± 0.12%' β '285714 Β± 12937' β 25895 β
β 1 β 'slower task' β '1147313 Β± 3.46%' β '1174041 Β± 9520.5' β '1642 Β± 66.76%' β '852 Β± 7' β 88 β
βββββββββββ΄ββββββββββββββββ΄ββββββββββββββββββββ΄βββββββββββββββββββββ΄βββββββββββββββββββββββββ΄βββββββββββββββββββββββββ΄ββββββββββChanges in HTML files as well as node scripts can be displayed immediately in a web browser.
Source files of HTML files are located in src/www/index.html.
To serve a static HTML file, run the following command:
$ npm run serve
or
$ npm run wwwNow you can try opening the HTML file with http://localhost:3000. Any changes will be updated immediately. (requires refresh)
Use the command below to quickly reset the code to its initial state:
# Code reset
$ npm run reset
# Additionally, initialize `package.json` and reset the modules.
$ npm run reset:allAnyone can contribute to the project by reporting new issues or submitting a pull request. For more information, please see CONTRIBUTING.md.
Please see the LICENSE file for more information about project owners, usage rights, and more.