Search code examples
node.jsnpmnodemonnpm-start

How do I run my nodejs application with nodemon?


Problem

Sorry in advance for asking a newbie question but I do hope anyone can help because I've been stuck for a few hours. I am currently working on a student portal assignment to develop a Backend API that reads from csv and stores into the database.

I'm having a very basic trouble of running or starting the Node Application.

Project Directory

Assignment 
- .vscode
- external
    - config
    - controllers
    - services
    - app.js
    - external-system.Dockerfile
    - package.json
    - packagelock.json
    - router.js
    - server.js (localhost:5000)
- javascript
    - src
        - config
        - const
        - controllers
        - errors
        - utils
        - app.js
        - router.js
        - server.js (localhost:3000)
    - database
    - node_modules
    - .babelrc
    - .env
    - .env.sample
    - .eslintrc        
    - docker-compose.yml
    - package.json
    - packagelog.json
- file.csv

Anyway in short, the javascript folder is where I will have to retrieve the csv file, create the API and storage to the database for the full time students. The external folder is where I have to retrieve the information it and because they are not full time students. (FYI: The directory is given and fixed)

What I've tried

I tried an npm start to the javascript folder but I have the following error when trying to run localhost:3000.

> [email protected] prestart C:\Users\User\Desktop\Assignment\javascript
> npm run start:services && npm run build


> [email protected] start:services C:\Users\User\Desktop\Assignment\javascript
> docker-compose up -d

'docker-compose' is not recognized as an internal or external command, operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start:services: `docker-compose up -d`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start:services 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\User\AppData\Roaming\npm-cache\_logs\2020-09-13T15_27_31_396Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prestart: `npm run start:services && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] prestart script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

In javascript directory(package.json)

{
  ...
  "scripts": {
    "test": "jest",
    "build": "babel src --out-dir build",
    "prestart": "npm run start:services && npm run build",
    "start": "node ./build/server.js",
    "prestart:dev": "npm run start:services ",
    "start:dev": "nodemon --exec babel-node src/server.js",
    "start:services": "docker-compose up -d",
    "lint": "eslint \"src/**/*.js\""
  and so on...

In external directory(package.json)

{
  ...
  "scripts": {
    "test": "jest",
    "build": "babel src --out-dir build",
    "prestart": "npm run build",
    "start": "node ./build/server.js",
    "start:dev": "nodemon --exec babel-node src/server.js",
    "lint": "eslint \"src/**/*.js\""
  ... and so on ...

Would be great anyone could give some tips on how to resolve the errors or correct me whether I am running the application correctly. Appreciate it!


Solution

  • Seems like you do not have docker installed on your windows. Check this https://docs.docker.com/docker-for-windows

    But I am not sure that if you install just docker, the docker-compose will be also installed, in that case you would need also install https://docs.docker.com/compose/install/ there is a Tab for installing it on windows.

    Also I am not sure if you have a typo in docker-compose.yml file, I see that there is docker.compose.yml filename which is wrong.