Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jlenon7/.ts-node
https://github.com/jlenon7/.ts-node
Last synced: 9 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jlenon7/.ts-node
- Owner: jlenon7
- Created: 2023-10-07T10:01:44.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-09T11:35:28.000Z (about 1 year ago)
- Last Synced: 2024-10-05T23:41:32.422Z (3 months ago)
- Language: JavaScript
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Supporting TS with Node.js like Deno
> This repo was created with the goal of providing a way to
> support running `.ts` files anywhere on your machine using
> ESM or CommonJS in Node.js v20.x.🚨 Tested only in **MacOS** with Node.js **v20.8.0** 🚨
## Updating to Node.js v20.x
The easiest way is using [`nvm`](https://github.com/nvm-sh/nvm). To
install it run the following:```shell
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
```Now that `nvm` is installed, run the following to update Node.js:
```shell
nvm install 20.8.0
```To set v20.8.0 as your default for all your terminal sessions run:
```shell
nvm alias default 20.8.0
```## Installation and usage
Start cloning this repo to the **home directory** of your machine and installing it
dependencies:```shell
git clone https://github.com/jlenon7/.ts-node.git ~/.ts-node && cd ~/.ts-node && npm i && cd
```Let's add the `NODE_OPTIONS` environment variable to your
terminal profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
If you are using MacOS, your will probably be `~/.zshrc`:> For `~/.zshrc`:
```shell
echo 'export NODE_OPTIONS="--require=$HOME/.ts-node/register.cjs"' >> ~/.zshrc && source ~/.zshrc
```At this point you are able to run the following:
```shell
echo "console.log('Hello World!')" >> ~/Desktop/index.ts
node ~/Desktop/index.ts
```You could also use in npm projects, but you will need to install
`ts-node` and configure a `tsconfig.json` for your project:```shell
mkdir ts-project && cd ts-project
npm init -y
npm install ts-node -D
cp ~/.ts-node/tsconfig.json tsconfig.json
echo "console.log('Hello World!')" >> index.ts
node index.ts
```