Socket
Socket
Sign inDemoInstall

@swc-node/register

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swc-node/register

SWC node register


Version published
Weekly downloads
1.1M
decreased by-10.16%
Maintainers
1
Weekly downloads
 
Created

What is @swc-node/register?

@swc-node/register is an npm package that allows you to use SWC (a super-fast TypeScript/JavaScript compiler) to transpile your code on-the-fly when running Node.js applications. This package is particularly useful for developers who want to leverage the speed of SWC for TypeScript or modern JavaScript features without needing to precompile their code.

What are @swc-node/register's main functionalities?

On-the-fly TypeScript Compilation

This feature allows you to run TypeScript code directly in Node.js without precompiling it. The code sample demonstrates how to require the @swc-node/register package and run TypeScript code on-the-fly.

require('@swc-node/register');
const tsCode = `const greet = (name: string): string => `Hello, ${name}`;`;
console.log(greet('World'));

Modern JavaScript Syntax Support

This feature allows you to use modern JavaScript syntax (like ES6 arrow functions) in Node.js applications. The code sample shows how to require the @swc-node/register package and run modern JavaScript code on-the-fly.

require('@swc-node/register');
const es6Code = `const add = (a, b) => a + b; console.log(add(2, 3));`;
eval(es6Code);

Configuration Options

This feature allows you to customize the SWC compiler options. The code sample demonstrates how to pass configuration options to the @swc-node/register package to set the JavaScript target version.

require('@swc-node/register')({
  swc: {
    jsc: {
      target: 'es2017'
    }
  }
});
const code = `const x = async () => await Promise.resolve('done'); x().then(console.log);`;
eval(code);

Other packages similar to @swc-node/register

Keywords

FAQs

Package last updated on 08 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc