Coder Social home page Coder Social logo

typescript-es-modules-node-example's Introduction

Running TypeScript ES Modules with Node.js

Build Status License

Based on the Announcing a new experimental modules post from the Node team, this repository is an example of a TypeScript app running with the new experimental modules feature shipped with Node.js 12. As explained in the linked post, it's now possible to use import and export syntax in .js files, so ES Modules transpiled from TypeScript can be used out of the box ๐Ÿ˜Ž

Project tree

.
โ”œโ”€โ”€ lerna.json
โ”œโ”€โ”€ package-lock.json
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ packages
โ”‚ย ย  โ”œโ”€โ”€ app //--> TypeScript app transpiled as an ES Module, using es-module dependency
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ package-lock.json
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ package.json
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ tsconfig.json
โ”‚ย ย  โ””โ”€โ”€ es-module //--> ES Module written in TypeScript
โ”‚ย ย      โ”œโ”€โ”€ package-lock.json
โ”‚ย ย      โ”œโ”€โ”€ package.json
โ”‚ย ย      โ””โ”€โ”€ tsconfig.json
โ””โ”€โ”€ tsconfig.settings.json

Config

Node.js

  • type: module: New package.json field to treat all .js files in project as ES Modules, see app and es-module files.
  • --experimental-modules: Flag to enable new experimental modules feature.
  • --es-module-specifier-resolution=node: By default, file extensions are mandatory in import. This flag enable CommonJS-style automatic extension resolution behavior. This flag is required because TypeScript does not add imported file extension in transpiled code.

TypeScript

Run app

  1. Install Node.js 12 or type nvm use if you use nvm
  2. Install project dependencies with: npm install
  3. Start app with: npm run start
  4. Browse http://localhost:3000

You should see the following JSON response:

{
  "messages": ["Hello from ES Module dependency", "Hello from local ES Module"]
}

License

MIT ยฉ kevinpollet

typescript-es-modules-node-example's People

Contributors

dandv avatar dependabot[bot] avatar kevinpollet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

tipizy

typescript-es-modules-node-example's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.