I have an angular app running fine. Next, I need to write some rest services, so I thought I will create a node.js
server inside the same angular app as it will be just couple of APIs. I created a file at src\server\server.ts
and following is its content -
import express from 'express';
const app = express();
const port = 3000;
app.get('/', (req, res) => {
res.send('The sedulous hyena ate the antelope!');
});
app.listen(port, err => {
if (err) {
return console.error(err);
}
return console.log(`server is listening on ${port}`);
});
I get an error at line 1 itself on express -
import express
Module '"c:/Users/A12345/quiz-master/node_modules/@types/express/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flagts(1259)
index.d.ts(107, 1): This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
I am not getting as what is causing it. Following is my package.json
-
{
"name": "quiz-master",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"server": "tsc && node src/server/server.ts",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/common": "~8.2.14",
"@angular/compiler": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@fortawesome/fontawesome-free": "^5.12.0",
"@types/chart.js": "^2.9.5",
"angular-bootstrap-md": "^8.8.0",
"animate.css": "^3.7.2",
"chart.js": "^2.5.0",
"core-js": "^2.5.4",
"express": "^4.17.1",
"hammerjs": "^2.0.8",
"pg": "^7.14.0",
"pg-hstore": "^2.3.3",
"prismjs": "^1.17.1",
"rxjs": "~6.5.3",
"sequelize": "^5.21.3",
"sequelize-typescript": "^1.1.0",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.803.20",
"@angular/cli": "~8.3.20",
"@angular/compiler-cli": "~8.2.14",
"@angular/language-service": "~8.2.14",
"@types/express": "^4.17.2",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.1.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.5.3"
}
}