简体   繁体   中英

Setting up node.js with a typescript project

I currently have a typescript project in Web express 2013 which works. I want to add a nodejs server side functionality.

In my ts folder I have my game logic and now I added this file Server.Ts

///<reference path="d.ts/node.d.ts" />

var url = require('url'),
    path = require('path'),
    http = require('http')
        .createServer(function (request, response) {
            var dest = url.parse(request.url).pathname;
            console.log('url [' + dest + '] requested');
            response.writeHead(200, { 'Content-Type': 'text/html' });
            response.end('Hello World');
        }).listen(8080);

What is the next steps to get this steps working and do you think its a bad idea combinging the server and Client ts in the one project?

no, its not a bad approach to have server and client side code in the same project, but you should structure things into client(jquery etc.), server(node.js etc) and shared code (config, models, etc.). But if you've got a big client base, makeing it a separate git project may make sense as well.

To make it easier to develop for node, use Grunt . And to easily pass your transcode your .ts to a .js file, use a grunt task like grunt-typescript

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM