npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@better-builds/nodec

v0.5.4

Published

The unofficial node-application-to-standalone-executable compiler, complete with ESBuild support.

Downloads

26

Readme

@better-builds/nodec

The node compiler (nodec), or rather, unofficial node-application-to-standalone-executable compiler, complete with ESBuild bundling support.

Warning: This project is highly experimental and likely has bugs. If you notice anything strange, please report it. PRs are also welcome, too! Thanks!

Prerequisites

  • golang v1.16 or greater (the go command must be available in your system $PATH)
  • node v18 or greater

Installation

npm install @better-builds/nodec --save-dev

Usage

npx nodec --entry ./src/entrypoint.ts --name my-cool-app

The example, above 👆🏼, will compile your TypeScript file, using the nodec default Node.js version (20.12.0), and a resulting my-cool-app binary file with appear in your cwd. The resulting binary will match OS + ARCH of the machine where it is run.

If you want to cross-compile to multiple OS targets, you can provide multiple --target values for all the targets you desire:

npx nodec --entry ./src/entrypoint.ts --name my-cool-app --target linux-x64 --target macos-x64 --target macos-arm64 --target win-x64

You will then see four (4) different binaries in your cwd, each corresponding to the various OS + ARCH targets you've specified.

For more options, you can run npx nodec --help to see the help menu:

npx nodec --help

Options:
  --version      Show version number                                   [boolean]
  --entry        the entrypoint to your JavaScript or TypeScript application
                                                             [string] [required]
  --format       which module format your JavaScript and / or TypeScript code wi
                 ll be compiled to
                               [string] [choices: "cjs", "esm"] [default: "esm"]
  --name         the final outputted filename that represents your compiled appl
                 ication                            [string] [default: "my-app"]
  --noCleanup    if true, will leave all of the downloaded, bundled and compress
                 es assets in a temporary folder on your machine, so you can ins
                 pect the state of them               [boolean] [default: false]
  --nodeFlags    one or more node.js flags to automatically set when executing y
                 our compiled application (like --experimental-require-module, -
                 -experimental-default-type and others). for a list of available
                  flags, please refer to the official node.js documentation: htt
                 ps://nodejs.org/docs/latest/api           [array] [default: []]
  --nodeVersion  defines the version of NodeJS that will be used when compiling
                 your standalone executable. Must be an explicit version. Semver
                  ranges are not supported.        [string] [default: "20.12.0"]
  --outDir       if set, uses this dir as the location where your binaries will
                 be placed after compilation. Defaults to your CWD.
                  [string] [default: "/home/stratodyne/devlop/opensource/nodec"]
  --target       one or more os+arch compilation targets
  [array] [choices: "linux-x64", "macos-x64", "macos-arm64", "win-x64"] [default
                                                                : ["linux-x64"]]
  --help         Show help                                             [boolean]

Project Background

Motivation

You, as a software engineer, might prefer JavaScript or TypeScript as your primary language of choice. You might also prefer the feature set and APIs available in Node.js, and you're looking to compile a portable, fully standalone executable file you can share with your users, one which doesn't require them to have npm, node or any other toolchain installed to use.

If this sounds like you, then you're in the right place!

Similar Libraries

Here are some alternate libraries you might be interested in instead, which have their own unique pros and cons. These libraries definitely helped inspire the creation of nodec

How nodec works

NodeC is a slightly different take at the Node.js single file executable compilation story. It downloads an official Node.js build for your target OS + ARCH combinations, compiles your JavaScript or TypeScript entry point with ESBuild to a valid ESM JS target that matches your expected Node.js target version, then uses the Golang compiler to embed Node and your bundled JavaScript into a cross-compiled binary application.

The resulting compiled binary then inflates your JavaScript bundle and your chosen Node.js target at runtime and executes them, piping all stdio to your user.


Contributing

  • Ensure you have the prerequisites (mentioned above 👆🏼) installed on your system
  • Clone this repo
  • Run ./repo-setup.sh

Happy hacking!