Skip to content

Using with Node

Alexandre Rogozine edited this page Mar 17, 2022 · 3 revisions

Using LINQ To Typescript with Node

Setting Up

Ensure that you're using Current or LTS version of Node

Run npm init to setup the project. Specify "type": "module".

Run npm install linq-to-typescript.

Using with JavaScript

Create index.js with the following,

import{range}from"linq-to-typescript";constprimeNumbers=range(2,10000).select((i)=>[i,Math.floor(Math.sqrt(i))]).where(([i,iSq])=>range(2,iSq).all((j)=>i%j!==0)).select(([prime])=>prime).toArray();asyncfunctionasyncIterable(){forawait(constiofrange(0,10).selectAsync(async(x)=>x*2)){console.log(i);}}asyncIterable();console.log(primeNumbers);

then run node index.js

Using with TypeScript

Ensure that you have TypeScript installed npm install typescript -g

Run tsc --init to create the tsconfig.json file

Configuring tsconfig.json

  • Update the Typescript configuration file to target ES2019.
  • Add the ES2019 to "lib" under "compilerOptions"
  • Set "strict": true under "compilerOptions"

Add index.ts file with the following,

import{range}from"linq-to-typescript"constprimeNumbers=range(2,10000).select((i)=>[i,Math.floor(Math.sqrt(i))]).where(([i,iSq])=>range(2,iSq).all((j)=>i%j!==0)).select(([prime])=>prime).toArray()asyncfunctionasyncIterable(){forawait(constiofrange(0,10).selectAsync(async(x)=>x*2)){console.log(i)}}asyncIterable()console.log(primeNumbers)

Run tsc to compile the index.ts to index.js

Run node index.js

Clone this wiki locally