How do I run my nodejs application with nodemon? - node.js

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.
> student-portal-system#1.0.0 prestart C:\Users\User\Desktop\Assignment\javascript
> npm run start:services && npm run build
> student-portal-system#1.0.0 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! student-portal-system#1.0.0 start:services: `docker-compose up -d`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the student-portal-system#1.0.0 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! student-portal-system#1.0.0 prestart: `npm run start:services && npm run build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the student-portal-system#1.0.0 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!

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.

Related

Npm script fails - '.' is not recognized as an internal or external command

This is the error log
'.' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cloudenly-hr-microservice#1.0.0 prestart: `sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the cloudenly-hr-microservice#1.0.0 prestart script.
Here is the script
"lint": "eslint",
"test": "export NODE_ENV=test && mocha --timeout 100000",
"prestart": "./node_modules/.bin/sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all",
"start": "./node_modules/pm2/bin/pm2 start pm2server.config.js",
"poststart": "./node_modules/pm2/bin/pm2 log HumanR"
You're on Windows, but trying to run a script designed for linux (it has linux path separators, which confuse Windows).
Inside an npm script, you can refer to locally installed package binaries by name. Doing so will eliminate your path issue.
"test": "export NODE_ENV=test && mocha --timeout 100000",
"prestart": "sequelize db:migrate && sequelize db:seed:all",
"start": "pm2 start pm2server.config.js",
"poststart": "pm2 log HumanR"
You might also run into an issue with the export NODE_ENV=test command. You'll need cross-env for that.
npm install --save-dev cross-env
Then in package.json:
"test": "cross-env NODE_ENV=test mocha --timeout 100000",
Does .bin folder in "./node_modules/.bin/sequelize db:migrate && ./node_modules/.bin/sequelize db:seed:all" exists?
I have something similar in a project, but I do this:
"db:seed": "npm run _db -- db:seed:all",
"db:create": "npm run _db -- db:create",
"db:migrate": "npm run _db -- db:migrate",
"db:init": "./scripts/create_and_seed_db.sh",
"_db": "node ./node_modules/sequelize-cli/lib/sequelize",

npm run build works fine on local machine but shows error on remote ubuntu server

I'm trying to deploy my MERN app on the digital ocean remote ubuntu server. After git clone, I did npm install to my root folder, client folder, and server folder. But when I tried to run npm start from the root folder then only the server app was running and an error came on the client-side. So I did cd into the client folder and tried the command npm run build (which I did on my local machine as well and the optimized build got created successfully) but it showed the below error on the remote server
> client#0.1.0 build /home/nishant/apps/rentaporta/client
> react-scripts build
Creating an optimized production build...
The build failed because the process exited too early. This probably means the system ran out of memory or someone called `kill -9` on the process.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client#0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client#0.1.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! /home/nishant/.npm/_logs/2020-10-27T05_22_30_755Z-debug.log
I deleted node_modules, package-lock.json, and tried the npm ci command as well but there was no improvement. My folder structure is
root
client
server
Below is my package.json script in root folder
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"client-install": "npm install --prefix client",
"server-install": "npm install ---prefix server",
"server": "npm start --prefix server",
"client": "npm start --prefix client",
"build-client": "npm run build --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"start": "npm run server-install & concurrently \"npm run build-client\" \"npm run server\""
},
Please, someone, help me. If you need more explanation I'm ready to put more details as needed.
finally, I figured out the problem. My remote ubuntu server had 1GB ram but there was no swap memory. I used the command sudo free -h, and found swap memory was 0. So, I followed this article (https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04) to create the swap memory, and finally, my app got deployed.
Also, cd into your client folder and run this command in the terminal-
$ export NODE_OPTIONS=--max-old-space-size=8192

npm ERR! missing script: deploy

I am deploying my application to github pages but when I run command npm run deploy but i get error
npm ERR! missing script: deploy
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\whoami\AppData\Roaming\npm-cache\_logs\2020-02-05T16_46_06_946Z-debug.log
I have defined deploy in my package.json file
...
"scripts": {
"test": "jest --watchAll --verbose --coverage --runInBand",
"start": "node index.js",
"predeploy":"npm run build",
"deploy":"gh-pages -d build"
}
...
make sure you have save package.json file. In my case i have not saved it so that is why error is coming
Please check the terminal path. In my case, I forgot to change the directory inside my project.
Simply type the following:
cd *name-of-your-project*
Please close the current working terminal and open new terminal and try the command again.

'sed' is not recognized as an internal or external command in Windows

I'm using gatsby mate portfolio but recent local development shows error when I run npm start:
'sed' is not recognized as an internal or external command,
operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gatsby-starter-mate#2.5.1 fix-medium-plugin: `sed -i' ' 's//latest//g' ./node_modules/gatsby-source-medium/gatsby-node.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gatsby-starter-mate#2.5.1 fix-medium-plugin script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
It seems that it's not properly escaping s //
Here's package.json copy of the line it specified:
"name": "gatsby-starter-mate",
"version": "2.5.1",
"description": "Gatsby v2 starter to create a top notch portfolio!",
"main": "index.js",
"scripts": {
"fix-medium-plugin": "sed -i' ' 's/\/latest//g' ./node_modules/gatsby-source-medium/gatsby-node.js",
"prepare": "npm run fix-medium-plugin && gatsby clean",
"build": "npm run prepare && gatsby build",
"develop": "npm run prepare && gatsby develop",
"start": "npm run develop",
"serve": "npm run build && gatsby serve -p 9000",
"lint": "eslint ./src",
"setup": "node ./bin/setup.js",
"e2e:open": "cypress open",
"e2e:ci": "DETERMINISTIC=true start-server-and-test serve http://localhost:9000 'percy exec -- cypress run'"
},
sed is a Unix command. You're likely within powershell in VSCode, you can still use this Gatsby starter you'll just need to run npm start within a unix terminal.
You can install cygwin path into your gatsby directory and enter npm start there and it will run successfully.
I have created a new gatsby project using this mate starter reached the same problem you are having and then confirmed with the creator of mate that there are no alternative solutions at this time other than running it via a unix terminal. Here is a link to the commit that occured on the 21st October 2019 that caused this problem for you and there you will find EmaSuriano's solution to your problem :)

vuejs app deploy to aws with eb cli. Error on instance Following services are not running: application

I have a vuejs app that I am trying to deploy to aws via elastic beanstalk cli. I get the error Following services not running: application and I'm not sure what that means. when I look at the logs I get
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the start script 'node build/dev-server.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the ntertainus package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node build/dev-server.js
This is the first time I have tried to use the cli and hoping someone can help me out I would appreciate that a lot
here is my the part of the package.json file that I think is failing
"scripts": {
"dev": "npm start",
"start": "node build/dev-server.js",
"build": "node build/build.js",
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
"e2e": "node test/e2e/runner.js",
"test": "npm run unit && npm run e2e",
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
},

Resources