2017-03-06 3 views
-1

私はAngular2 Appを開発しており、簡単なWebサービスを構築しようとしています。したがって、Typsecriptをサーバー上で使用したいと考えています。標準Typescript + Nodejsサーバー定型テンプレートはありますか?

私はこのことについてインターネットでちょっと見たことがあり、ノードとエクスプレスでTypsecriptを手動でセットアップするブログ記事がいくつか見つかりました。

Typescriptとノード(およびおそらくExpress)のWebサービスでプロジェクトを開始するだけの標準的な定型テンプレートがあるのでしょうか?

編集:私は、質問とは異なるスピンがあると思います:Typescript用のWebフレームワークビルドはありますか?

EDIT2:私はこれに適切な答えを見つけることができませんでしたので、Typescriptから離れ、Sailsの完全なフレームワークを使い、Javascriptバージョンを使用しました。

+1

Downvoter、コメントしてください。 –

答えて

1

Nodejs Visual Studio用ツールには、いくつかのExpressスターターテンプレートが付属しています。残念ながら、彼らは古いバージョンのExpressを使用しており、開始するには良い場所ではありません。

TypeScriptを問題に適用する最も良い方法は、いくつかのJavaScriptから始めることです。 Visual Studioのコードや他の多くのIDEを使用している場合、どのExpressテンプレートプロジェクトでもうまくいくでしょうし、タイピングを自動的にインストールすることができます。

またはnpm i --save @types/expressです。

JavaScript/TypeScriptフロントエンドでNodeJSバックエンドを他のバックエンドテクノロジよりも使用して得られるものは何もありません。シリアル化バリアは文字通りそれらをカプセル化するので、バックエンドが最も理にかなったものを使用してください。

モデルのインターフェイス宣言を共有する場合は、他の言語のソースファイルからTypeScriptを生成するツールがたくさんあります。

+0

私は単純なWebサービスを構築しようとしています。私は、ノードサービスのスピンアップが他のテクノロジーより簡単になると聞いています。それで、なぜ私はそれがマイクロサービスのための良い選択であろうと思ったのですか? –

+0

文字通り、アプリケーションをテストするためのAPIが必要な場合は、npm:json-serverなどの任意のディレクトリからファイルをホストしてHTTPリクエストを行うことができます。これはテストのためだけのものですが、うまくいくものではありません。 –

+1

コメントを投稿してください。 –

0

https://github.com/dwyl/hapi-typescript-example

は、私はまた、アプリtypoescript例の帆を開始https://github.com/aslanvaroqua/sails-ts

基本骨子:

/** 
* WelcomeController 
* 
* @description :: Server-side logic for managing Welcomes 
* @help  :: See http://links.sailsjs.org/docs/controllers 
*/ 

import e = require('express'); 
import util = require('util'); 

declare const sails: any; 

const WelcomeController = { 
    index: function (req: e.Request, res: e.Response, next: Function) { 
    console.log('index() from WelcomeController.ts'); 
    sails.models.welcome.find().limit(1).then((welcome) => { 
     /// TODO: add logger 
     console.log(`welcome page rendering w/ message ${welcome[0].message}`); 
     return res.render('welcome', { 
     welcome: welcome[0].message 
     }); 
    }).catch((err:Error) => { 
     console.error(err.message); 
     return res.render('500', err) 
    }); 


    }, 
    config: function (req: e.Request, res:e.Response, next:Function) { 
    console.log('config() from WelcomeController.ts'); 
    return res.status(200) 
     .send('<h1>sails.config :</h1><pre>' + util.inspect(sails.config) + '<pre>'); 
    } 
}; 

module.exports = WelcomeController; 

モデル

export class Welcome { 
    attributes: any = { 
    id: { 
     type: 'integer', 
     primaryKey: true 
    }, 
    message: { 
     type: 'string', 
     required: true, 
     defaultsTo: 'default message' 
    } 
    }; 
} 

typings.json

{ 
    "dependencies": { 
    "bluebird": "registry:npm/bluebird#3.5.0+20170314181206", 
    "connect": "registry:dt/connect#3.4.0+20160510010627", 
    "express": "registry:dt/express#4.0.0+20170118060322", 
    "express-serve-static-core": "registry:dt/express-serve-static-core#4.0.0+20170324160323", 
    "sails": "registry:npm/sails#0.12.0+20160610190623", 
    "serve-static": "registry:dt/serve-static#1.7.1+20161128184045" 
    }, 
    "globalDependencies": { 
    "es6-shim": "registry:dt/es6-shim#0.31.2+20160726072212", 
    "node": "registry:dt/node#7.0.0+20170322231424", 
    "socket.io": "registry:dt/socket.io#1.4.4+20170313110830" 
    } 
} 

テスト

describe("HashSet", function() { 
    it("should behave like a set, removing duplicates", function() { 

    }); 
}); 
関連する問題