When trying to create a release pipeline in Azure DevOps (I have used a Nodejs application) it exits with an error. ##[error]Bash exited with code '1' - node.js

NodeJs application that I have been trying to deploy, always shows an error:
[error]Bash exited with code '1'.
{
"name": "test1",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"start": "node app.js",
"dev": "nodemon app.js",
"build": " "
},
"keywords": ["app.js"],
"author": "",
"license": "ISC",
"dependencies": {
"bcryptjs": "^2.4.3",
"connect-flash": "^0.1.1",
"ejs": "^2.6.2",
"express": "^4.17.1",
"express-ejs-layouts": "^2.5.0",
"express-session": "^1.16.2",
"i": "^0.3.6",
"mongoose": "^5.6.5",
"passport": "^0.4.0",
"passport-local": "^1.0.0"
},
"devDependencies": {
"nodemon": "^1.19.1"
},
"description": ""
}

First, Please check the path in the artifacts weather the files that are required exists in the artifacts or not. Download the artifact that you are trying to deploy and make sure the package.json and app.js is in the root directory (or in the deirectory that you are trying to deploy).
For further diagnoisis i think you need to provide your question with more detail descriptions like
What build script was used to make the artifact.
What environment was used for app deployment.

Related

Nodejs, how to deploy typescript project which reference multiple local projects to Heroku?

I have a nodejs typescript project with this package.json:
{
"name": "construction-node-service",
"version": "1.0.0",
"description": "Fine Chat App Nodejs Service",
"main": "app.js",
"types": "./#types",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"debug": "nodemon --inspect src/app.ts",
"dev:debug": "nodemon --config nodemon.json --inspect-brk src/index.ts",
"tsdebug": "ts-node-dev --respawn ",
"tsdev": "nodemon --exec ts-node tt.ts",
"compile": "tsc && node dist/app.js",
"dev": "nodemon -e ts --exec npm run compile",
"dev:server": "nodemon --watch ./**/*.ts --exec ts-node src/app.ts",
"start": "node dist/app.js"
},
"engines": {
"node": "12.22.1"
},
"author": "Ayman Shokry",
"license": "ISC",
"dependencies": {
"#types/compression": "^1.7.0",
"bson-objectid": "^2.0.1",
"compression": "^1.7.4",
"express": "^4.17.1",
"generate-unique-id": "^2.0.1",
"global-shared-node": "file:../../../public-api/NodeJs/global-shared-node",
"public-dao-node": "file:../../../public-api/NodeJs/public-dao-node",
"helmet": "^4.6.0",
"moment": "^2.29.1",
"mongoose": "^5.12.1",
"multer": "^1.4.2",
"mysql2": "^2.1.0",
"reflect-metadata": "^0.1.13",
"sequelize": "^6.6.2",
"sequelize-typescript": "^2.1.0",
"socket.io": "^2.3.0"
},
"devDependencies": {
"#types/express": "^4.17.11",
"#types/node": "^15.0.1",
"#types/sequelize": "^4.28.9",
"#types/validator": "^13.1.3",
"babel-cli": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"pm2": "^4.5.0",
"rimraf": "^3.0.2",
"sequelize-cli": "^5.5.1",
"ts-node": "^9.1.1",
"ts-node-dev": "^1.1.6",
"typescript": "^4.2.4"
}
}
I thought if I can copy the 2 local project src files to my project src folder before deploy but I think this solution is annoying
as you see I referenced 2 local projects on my HDD the question is how can I deploy this project with the 2 project dependencies to Heroku.thanks
As per the questions and suggestions on the internet, the answer is NO.
According to many communities and experts, Heroku's model is to run one app per dyno (and often many dynos for a single app).
But wait, there is a case in which two servers are deployed to a single dyno and it worked too. You can check it here: https://medium.com/#nadayar/heroku-fu-multiple-servers-on-one-dyno-6fc68d57b373
Hope this solves your problem!

Travis CI showing build error for my expressjs app despite showing all tests passed

I have integrated Travis CI into my github repo called Banka which contains expressjs application and some html and css files.
On building, travis shows all my test which I wrote in mocha and chai as passing but yet it finally reports "build error" and surprisingly enough, can't point where the error is.
I changed to latest node and npm versions and still, no change
--package.json
{
"name": "Banka",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www",
"test": "mocha"
},
"engines": {
"node": "~10.15.3",
"npm": "~6.4.1"
},
"dependencies": {
"bcrypt": "^3.0.5",
"body-parser": "~1.8.1",
"chai": "^4.2.0",
"chai-http": "^4.2.1",
"cookie-parser": "~1.3.3",
"debug": "~2.0.0",
"dotenv": "^1.2.0",
"express": "~4.9.0",
"express-jwt": "^3.0.1",
"jade": "~1.6.0",
"jsonwebtoken": "^5.0.2",
"mocha": "^6.1.2",
"morgan": "~1.3.0",
"passport": "^0.2.2",
"passport-local": "^1.0.0",
"request": "~2.51.0"
}
}
Here is what Travis is showing : https://travis-ci.com/NawasNaziru/Banka/builds/108177363
I expect to see "build passing" since, all my tests passed.
The cause of the problem is that mocha doesn't close and handover to Travis after running the written tests. Hence, the reason why, travis reports timeout. To fix that, simply add the --exit flag in your package.json next to mocha like this
{
"test" : "mocha --exit"
......
}

npm run scripts does not working

I have just initialized a new project with Node.js and trying making the scripts in package.json file to be working.
For example I have the next package.json file:
{
"name": "my-app-name",
"version": "1.0.0",
"description": "Description server",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node app.js"
},
"author": "Something LTD",
"license": "ISC",
"dependencies": {
"body-parser": "^1.18.3",
"cron": "^1.3.0",
"crypto": "^1.0.1",
"docusaurus-init": "^1.0.2",
"exceljs": "^1.5.0",
"express": "^4.16.3",
"express-limiter": "^1.6.1",
"jsonwebtoken": "^8.3.0",
"mongojs": "^2.6.0",
"npm": "^6.1.0",
"point-in-polygon": "^1.0.1",
"request": "^2.87.0",
"socket.io": "^2.1.1",
"socket.io-redis": "^5.2.0",
"xmldom": "^0.1.27"
},
"devDependencies": {
"t4u": "^1.0.0"
}
}
Then I either trying run npm test or npm start or npm run start
but all of them just doing nothing and returns nothing in console. Even the test script just not printing anything.
I have tried to do:
npm config set --ignore-scripts false
However that did not work.
npm config set ignore-scripts false
Was solved the issue.
npm run-script start worked for me (npm run is an alias to npm run-script as stated in doc but not sure why alias didnt work)
hope this helps people who are still facing the issue after setting ignore-script as false
On Windows you can also edit directly a file on the following location
C:\Users\[Your username]\.npmrc
and set ignore-scripts=false

Why does NodeJS require me to use the full directory for downloaded modules?

For something like Express for example, which does not come with Node by default. I have to use var express = require('C:/Users/User/node_modules/express'); instead of just var express = require('express');. I notice the modules which come by default such as http aren't in the same location as the ones I install. So what do I need to do in order to not have to write the whole directory. If it makes any difference I keep all my Node projects in C:/Node/, not the default one.
This is happening because you probably don't have node modules installed locally. For that you need a package.json file which you can get by running
npm init
This will ask you some questions about your project and will set up node locally. A package.json file will be created which should look something like this (without dependencies).
{
"name": "express-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "Link to your repository"
},
"author": "",
"license": "ISC",
"dependencies": {
"bcrypt": "^1.0.2",
"body-parser": "^1.17.2",
"chalk": "^2.0.1",
"compression": "^1.7.0",
"cookie-parser": "^1.4.3",
"cors": "^2.8.4",
"express": "^4.15.3",
"glob": "^7.1.2",
"moment": "^2.18.1",
"mongoose": "^4.11.3",
"morgan": "^1.8.2",
"passport": "^0.3.2",
"path": "^0.12.7",
"yargs": "^8.0.2"
}
}
You can then add the node modules you want by putting them in dependencies and running
npm install
If you want to add node modules from commond line you can use
npm install package-name --save

ember/npm addon with dependencies/ devDependencies

I have created an ember addon which relies on gulp derived packages to build, so in the addon it has the following in package.json.
When the addon is included in the main application, the build fails due to the various gulp modules being missing. The addon is in the devDependencies section of the main application.
The addon also builds into the main application when it is in through npm link. My question is how should the addon dependencies be handled so the main application builds without a local copy of the module?
Update: I think the problem is that the package does a gulp build after the postinstall which elevates the gulp devDependencies into real dependencies. Is this correct?
Addon JSON file
{
"name": "My Addon",
"version": "0.0.0",
"description": "The default blueprint for ember-cli addons.",
"directories": {
"doc": "doc",
"test": "tests"
},
"scripts": {
"build": "ember build",
"start": "ember server",
"test": "ember try:each",
"postinstall": "gulp build && bower install"
},
"repository": {
"type": "git",
"url": "git://github.com/myaddon.git"
},
"engines": {
"node": ">= 0.12.0"
},
"author": "",
"license": "MIT",
"devDependencies": {
"bootstrap": "^4.0.0-alpha.5",
"broccoli-asset-rev": "^2.4.5",
"broccoli-funnel": "^1.0.9",
"ember-ajax": "^2.4.1",
// more ember modules
"find-root": "^0.1.1",
"font-awesome": "^4.7.0",
"glob": "^4.5.3",
"gulp": "^3.9.1",
"gulp-clean-css": "^2.2.1",
"gulp-concat": "^2.6.0",
"gulp-connect": "^2.2.0",
"gulp-filter": "^3.0.1",
"gulp-git": "^1.4.0",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^1.5.2",
"gulp-task-loader": "^1.2.1",
"gulp-template": "^3.0.0",
"gulp-uglify": "^1.2.0",
"gulp-zip": "^3.0.2",
"lazypipe": "^1.0.1",
"loader.js": "^4.0.10",
"run-sequence": "^1.1.2"
},
"keywords": [
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.7"
},
"ember-addon": {
"configPath": "tests/dummy/config"
}
}
The addon's dependencies are needed to build application (that includes addon), should be listed in dependencies section. The devDependencies of a package that is included as dependency of another package, are ignored.
There is other solution to add packages into an application. You can create a blueprint in your addon that will be called every time an application build with it or install it.

Resources