'npm run server error '.' is not recognized as an internal or external command,

I ran into this problem with angular and npm and I'm yet to find a solution for it . The project I'm working is this angular project from github , this exact code worked for others so the issue is probably from my side .

the command npm run server gives the following error:

[email protected] server ./server.ts

'.' is not recognized as an internal or external command, operable program or batch file.

The server script in package.json file:

"server": "./node_modules/.bin/ts-node -P ./server.tsconfig.json ./server.ts"

I ran the npm install command first and all the files and dependencies are succefully installed so I'm not sure what's the problem .



Solution 1:[1]

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);
});

Solution 2:[2]

I think the problem with the / itself so replace it to something like that .\\node_modules\\.bin\\ts-node -P ./server.tsconfig.json ./server.ts

Solution 3:[3]

Actually the problem is with "/" in the command on windows. Replace it with "" and it will work like as follows

.\node_modules\.bin\ts-node -P .\server.tsconfig.json .\server.ts

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mahdi Saber
Solution 2 Hassan Gad
Solution 3 vikas sharma viky