Boss-machine project - server not starting

Hi all, I’m working on the Boss-Machine project https://www.codecademy.com/paths/back-end-engineer-career-path/tracks/becp-build-a-back-end-with-node-express-js/modules/fscp-api-project-boss-machine/informationals/bapi-p4-boss-machine

I’m not able to get the server to start. I’ve done the initial coding to start the server. However, when I run npm run start in the console, I get this error message.

Here’s my code:

const express = require('express');
const app = express();

const bodyParser = require('body-parser');
const cors = require('cors');

module.exports = app;

/* Do not change the following line! It is required for testing and allowing
*  the frontend application to interact as planned with the api server
*/
const PORT = process.env.PORT || 4001;

// Add middleware for handling CORS requests from index.html
app.use(cors());



// Add middware for parsing request bodies here:
app.use(bodyParser.json());

// Mount your existing apiRouter below at the '/api' path.
const apiRouter = require('./server/api');

app.use('/api', apiRouter );

// This conditional is here for testing purposes:
if (!module.parent) { 
  // Add your code to start the server listening at PORT below:
  app.listen(PORT,()=>{
    console.log(`Server is listening on ${PORT}`);
});
}

Please help.
Thanks in advance.
Jeff

Hi there.

Did you remember to run npm install before working on the project / attempting to run the server?

The error that you are getting is 'nodemon' is not recognized as an internal or external command.

When you’re running npm run start, what actually happens is the following command is run: nodemon --watch server.js --watch server/. If nodemon isn’t installed, the command will fail with the error you’re getting.

nodemon is listed as a dependency in the project’s package.json file, so ought to have been / should be installed by running npm install.

Thank you for your reply. I thought for sure it was something simple like that. However, when I ran

npm install

and then

npm run start

I am getting the same error statement :man_facepalming:

Here’s my package.json file

{
  "name": "build-apis-boss-machine",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "cross-env PORT=8000 mocha --watch",
    "start-dev": "webpack -w & nodemon --watch server.js --watch server/",
    "start": "nodemon --watch server.js --watch server/",
    "postinstall": "webpack"
  },
  "author": "Codecademy",
  "license": "ISC",
  "dependencies": {
    "axios": "^0.16.2",
    "body-parser": "^1.17.2",
    "chai": "^4.1.1",
    "cors": "^2.8.5",
    "cross-env": "^5.1.1",
    "express": "^4.15.4",
    "mocha": "^6.1.3",
    "morgan": "^1.8.2",
    "nodemon": "^1.11.0",
    "supertest": "^3.0.0"
  },
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "babel-preset-stage-2": "^6.24.1",
    "faker": "^4.1.0",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.6",
    "react-router": "^3.0.0",
    "redux": "^3.7.2",
    "redux-thunk": "^2.2.0",
    "webpack": "^3.5.5"
  }
}

Very puzzled. I ran the solution code and of course, the server launches. Then I compared my server.js file and package.json files with the solution code and found no differences. I’m not sure what else to look at, no other file was altered by me so they should be identical. I completed as much of the project as I could. I could not test the code, only compare it to solution code to see if I’m on the right track.

I’m moving on from the Node/Express module. It has been the most unsatisfying module of the entire pathway so far. Maybe it is just my ineptness, but my frustration level with this module is much higher compared to the rest of the pathway. :weary:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.