angular js 2 basic setup issues

334 Views Asked by At

I have PHP and JavaScript background and never worked with nodejs or angular js with full hand , just a basic understanding of these js.

I started to learn angular js 2 but find very difficulties to set up first example.

node v 5.6.0 and npm version 3.7.2 on ubuntu 14.04

I am following this article with a change -- that tsd has been deprecated so used typings instead of tsd. below is my folder structure. angular 2 set up

But when I run gulp buildServer on terminal it gives below errors

Gulp Error

I may be doing very basic error , kindly help me to solve this and if required more information then tell me.

server.ts has below code

import express = require('express');
import path = require('path');
var port: number = process.env.PORT || 3000;
var app = express();

app.use('/app', express.static(path.resolve(__dirname, 'app')));
app.use('/libs', express.static(path.resolve(__dirname, 'libs')));

var renderIndex = (req: express.Request, res: express.Response) => {
    res.sendFile(path.resolve(__dirname, 'index.html'));
}

app.get('/*', renderIndex);

var server = app.listen(port, function() {
    var host = server.address().address;
    var port = server.address().port;
    console.log('This express app is listening on port:' + port);
});
2

There are 2 best solutions below

2
On BEST ANSWER

You need to get the type definitions for node and server-static.

typings install node --ambient --save
typings install serve-static --ambient --save
typings install mime --ambient --save

You need mime since serve-static relys on it.

7
On

It says cannot find module 'path' and then again with http and so on. Also errors with duplicate identifier in my experience are due to using old version of npm because since npm v3.0 it tries to make all dependencies flat.

I'd try to rm -rf node_modules, install newest stable node and npm, run again npm install and then try running your gulp. Or at least check what are your npm and node versions.