I'm facing difficulty in create a build of my Node Js API application.
Below is how my package.json file looks like:
{
"name": "node-mongo-registration-login-api",
"version": "1.0.0",
"description": "NodeJS + MongoDB API for User Management, Authentication and Registration",
"main": "server.js",
"license": "MIT",
"scripts": {
"start": "node ./server.js",
"start-dev": "nodemon ./server.js",
"build": "react-scripts build"
},
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"express-jwt": "^5.3.3",
"jsonwebtoken": "^8.5.1",
"mongodb": "^3.5.6",
"mongoose": "^5.9.10",
"react-scripts": "^3.4.1",
"rootpath": "^0.1.2"
},
"devDependencies": {
"nodemon": "^2.0.3"
}
}
When I run npm run build, it gives below error:
Could not find a required file.
Name: index.html
Searched in: C:\Users\Tejas\Desktop\React\Templates\node-mongo-registration-login-api-master\public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-mongo-registration-login-api@1.0.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-mongo-registration-login-api@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Tejas\AppData\Roaming\npm-cache\_logs\2020-06-15T10_12_13_343Z-debug.log
I'm not sure why an index.html is needed in a server application where no UI is needed.
If you are just implementing API and don't have a react application, you don't need to build it. use npm run start
to start your server.