Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zaydek/esnode
Run JSX and TypeScript, powered by esbuild.
https://github.com/zaydek/esnode
Last synced: 3 months ago
JSON representation
Run JSX and TypeScript, powered by esbuild.
- Host: GitHub
- URL: https://github.com/zaydek/esnode
- Owner: zaydek
- License: mit
- Created: 2021-03-06T16:26:34.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-09-17T18:21:28.000Z (about 3 years ago)
- Last Synced: 2024-07-06T21:22:03.790Z (4 months ago)
- Language: TypeScript
- Homepage:
- Size: 118 KB
- Stars: 8
- Watchers: 3
- Forks: 2
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# esnode
esnode is the answer to the question: How do I run JSX or TypeScript on the server without build-steps?
esnode builds on [esbuild](https://github.com/evanw/esbuild) and
[source-map-support](https://github.com/evanw/node-source-map-support) (thanks [@evanw](https://github.com/evanw)!) to
enable transpilation on-the-fly for `.js`, `.jsx`, `.ts`, and `.tsx` files.Note that esnode does not type-check at build-time. If this is important to you, you may want to use
[ts-node](https://github.com/TypeStrong/ts-node) or [Deno](https://github.com/denoland/deno). Note that
[Deno](https://github.com/denoland/deno) is not largely compatible with the existing Node.js ecosystem. Therefore if
type-checking at build-time and interoperability with Node.js is important to you, you may want to use
[ts-node](https://github.com/TypeStrong/ts-node) or defer to VS Code and or `tsc` for type-checking.## Installation
To install esnode, simply install `@zaydek/esnode` and run `./node_modules/.bin/esnode`.
**NPM**
```sh
npm i --save-dev @zaydek/esnode
./node_modules/.bin/esnode [file]
```**Yarn**
```sh
yarn add --dev @zaydek/esnode
./node_modules/.bin/esnode [file]
```Finally, create and run a JSX or TypeScript file:
```ts
// hello.ts
function hello(who?: string): string {
return `Hello, ${who ?? "world"}!`
}console.log(hello())
``````sh
% ./node_modules/.bin/esnode hello.ts
Hello, world!
```For convenience, you may want to alias esnode as `alias esnode=./node_modules/.bin/esnode`. To alias esnode globally,
add `alias esnode=./node_modules/.bin/esnode` to your `~/.bash_profile`.## CLI
```sh
esnode [file]
esnode runs a JavaScript or TypeScript file using the Node.js runtime. This is
almost the same as 'node [file]' except that 'esnode [file]' is compatible with
'.js', '.jsx', '.ts', and '.tsx' files. You may even interoperate JavaScript and
TypeScript.Your entry point and its dependencies are transpiled on-the-fly by esbuild.
esbuild is configured to not bundle 'package.json' dependencies at build-time;
these dependencies use 'require' at runtime.Note that '.ts' and '.tsx' files are not type-checked. You may use VS Code or the
TypeScript CLI 'tsc' for type-checking. To add the TypeScript CLI, use
'npm i --save-dev typescript' or 'yarn add --dev typescript'.Examples
% ./node_modules/.bin/esnode hello.ts
Hello, world!% alias esnode=./node_modules/.bin/esnode
% esnode hello.ts
Hello, world!% STACK_TRACE=true esnode hello.ts
Hello, world!Repositories
esnode: https://github.com/zaydek/esnode
esbuild: https://github.com/evanw/esbuild```
## License
Licensed as MIT open source.