Git Product home page Git Product logo

express-typescript's Introduction

Express Generated Project to Typescript

Generate express project

  • npx express-generator <dir name>. To create express project with name.
  • npm install and npm start to start server at port 3000.

Converting to typescript

  • npm install --save-dev typescript @types/cookie-parser @types/http-errors @types/morgan @types/node ts-node. Installs necessary dependencies in types for express.
  • npx tsc --init to create tsconfig file.
  • create a src folder and move /routes and app.js into it. Delete /views since we dont need it.

Note: since we ignoring the views, change res.render to res.send("text")

  • Change the tsconfig's configs.
  • Rename all the extensions in /src from .js to .ts.
  • Once renamed, change all imports from require to import syntax.
  • Since app.js is repositioned, in bin/www file change
- var app = require('../app');
+ var app = require('../dist/app');

Starting server

  • npm start will start server at port 3000.

Note: will just compile the .ts files and starts the server. DOES NOT WATCH FOR FILE CHANGES

Debugging typescript

  • Create a .vscode/launch.json file if working with vsc and copy below content. More info
  • Intentionally /.vscode folder was not git ignore. can see launch.json
  • Add a debugger point in the file and press f5 to start server in debugger mode.

express-typescript's People

Contributors

sriramrudraraju avatar

Watchers

James Cloos avatar  avatar

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.