angular-course
angular-course copied to clipboard
npm run sever is not working
C:\Users\home\3-services\3-services>npm run server
[email protected] server ./node_modules/.bin/ts-node -P ./server.tsconfig.json ./server.ts
'.' is not recognized as an internal or external command, operable program or batch file.
C:\Users\home\3-services\3-services>
This repository seems to be outdated. I had the same problem.
In order to fix the issue, try this command:
.\node_modules\.bin\ts-node -P .\server.tsconfig.json .\server.ts
The content of server.ts
is as follows:
import * as express from 'express';
import {Application} from 'express';
import {getAllCourses} from './server/get-courses.route';
import {saveCourse} from './server/save-course.route';
const bodyParser = require('body-parser');
const app: Application = express();
app.use(bodyParser.json());
app.route('/api/courses').get(getAllCourses);
app.route('/api/courses/:id').put(saveCourse);
const httpServer = app.listen(9000, () => {
console.log('HTTP REST API Server running at http://localhost:' + httpServer.address().port);
});
For me, the Express server runs however when checking on the link i.e. localhost:9000 all I get is the above error message
Cannot GET /
Below is the output from npm run server
:
> [email protected] server C:\FisherSS\angular-course
> ts-node -P ./server.tsconfig.json ./server.ts
HTTP REST API Server running at http://localhost:9000
When I google, this is the link that comes up. Doing this fixe the issue in my case. Replace the "server" in package.json with this:
"server": "node ./node_modules/ts-node/dist/bin.js -P ./server.tsconfig.json ./server.ts"
What we are doing is side-stepping usage of the bash file and directly pointing to the binary as mentioned here.