Amazon Elastic Beanstalk npm cant find package.json - node.js

I'm very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk. I set up the instance and uploaded/deployed the site, but while the health is "Ok" the node.js logs show this repeated about 30 times:
npm ERR! enoent ENOENT: no such file or directory, open '/var/app/current/package.json'
npm ERR! enoent This is most likely not a problem with npm itself
npm ERR! enoent and is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! Please include the following file with any support request:
npm ERR! /var/app/current/npm-debug.log
npm ERR! Linux 4.1.13-19.31.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.2.3-linux-x64/bin/npm" "start"
npm ERR! node v4.2.3
npm ERR! npm v2.14.7
npm ERR! path /var/app/current/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
The problem is that my package.json does exist because I generated one with npm init. Any ideas on why it cant be found? Here is the package.json
{
"name": "testwebsite",
"version": "0.0.1",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"body-parser": "^1.13.3",
"express": "^4.13.3",
"express-session": "~1.0.0",
"socket.io": "^1.3.7"
},
"description": "my website",
"author": "Matt",
"engines": {
"node": ">=0.10.0"
},
"main": "server.js",
"devDependencies": {},
"license": "ISC"
}

From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.
For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".
[1] https://forums.aws.amazon.com/thread.jspa?messageID=476022

I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).
I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:
var app = express();
app.set('port', (process.env.PORT || 5000)); // 5000 was my original port
Then using this port in the app.listen method instead of my own custom port number:
app.listen(app.get('port'), function () {
console.log('Server has started! http://localhost:' + app.get('port') + '/');
});
More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

I was having these odd error on AWS EB as well. I was generally deploying using the CLI.
couple things to try.
make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers
i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.
hope this helps

I was having something similar whereby the elastic beanstalk deploy failed when using the eb cli. I realized that the elastic beanstalk config files had inadvertently been added to my .gitignore file causing the deploy to fail.

I had trouble with the zipping, etc. I recommend using CodePipeline and linking it to your github or AWS codecommit. Then, skip the build stage, and for the deploy stage click elastic beanstalk.
You will have to pause the process and open a new tab and go to EB and create a new environment. Make sure you click nodeJS in this example. Make sure you choose "sample code" so that AWS can set it up with their template. Once the EB is finished building you should have a link to the template that is functional.
Then you can go back to your CodePipeline tab and click on Elastic Beanstalk for deployment and you should find the EB you just made.
I recommend this process because it will automatically update every time you do a git change. This is better than zipping a file, etc.

Related

Unable to deploy React JS application on Azure App service

I was going through the some of the links to deploy React Js application on the azure app service. But i am facing some problem while deploying the application.
I have added all the necessary things like web.config file to public folder and also added build directory to the workspace.
Deploying web app on azure app service
Deploy Node.js to Azure App Service using Visual Studio Code
followed all the steps but getting below error when i try to deploy on azure app service. Before deploying i do run these commands
npm run build.
2020-08-19T10:44:45.762075166Z A P P S E R V I C E O N L I N U X
2020-08-19T10:44:45.762079567Z
2020-08-19T10:44:45.762083667Z Documentation: http://aka.ms/webapp-linux
2020-08-19T10:44:45.762088167Z NodeJS quickstart: https://aka.ms/node-qs
2020-08-19T10:44:45.762092268Z NodeJS Version : v12.16.3
2020-08-19T10:44:45.762096468Z Note: Any data outside '/home' is not persisted
2020-08-19T10:44:45.762100768Z
2020-08-19T10:44:45.789282727Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-08-19T10:44:45.792738514Z Build Operation ID: |OtQwveNuO0A=.83a2ec6c_
2020-08-19T10:44:47.255197638Z Writing output script to '/opt/startup/startup.sh'
2020-08-19T10:44:47.960307930Z Running #!/bin/sh
2020-08-19T10:44:47.960336532Z
2020-08-19T10:44:47.960345833Z # Enter the source directory to make sure the script runs where the user expects
2020-08-19T10:44:47.960355334Z cd "/home/site/wwwroot"
2020-08-19T10:44:47.960363235Z
2020-08-19T10:44:47.960370735Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-08-19T10:44:47.960378436Z if [ -z "$PORT" ]; then
2020-08-19T10:44:47.960386136Z export PORT=8080
2020-08-19T10:44:47.960393937Z fi
2020-08-19T10:44:47.960401238Z
2020-08-19T10:44:47.960408638Z echo Found tar.gz based node_modules.
2020-08-19T10:44:47.960416339Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2020-08-19T10:44:47.960424040Z echo "Removing existing modules directory from root..."
2020-08-19T10:44:47.960431740Z rm -fr /node_modules
2020-08-19T10:44:47.960439141Z mkdir -p /node_modules
2020-08-19T10:44:47.960446542Z echo Extracting modules...
2020-08-19T10:44:47.960453842Z $extractionCommand
2020-08-19T10:44:47.960461243Z export NODE_PATH="/node_modules":$NODE_PATH
2020-08-19T10:44:47.960468943Z export PATH=/node_modules/.bin:$PATH
2020-08-19T10:44:47.960476344Z if [ -d node_modules ]; then
2020-08-19T10:44:47.960483745Z mv -f node_modules _del_node_modules || true
2020-08-19T10:44:47.960491245Z fi
2020-08-19T10:44:47.960498446Z
2020-08-19T10:44:47.960505546Z if [ -d /node_modules ]; then
2020-08-19T10:44:47.960524748Z ln -sfn /node_modules ./node_modules
2020-08-19T10:44:47.960532849Z fi
2020-08-19T10:44:47.960540149Z
2020-08-19T10:44:47.960547550Z echo "Done."
2020-08-19T10:44:47.960554951Z npm start
2020-08-19T10:44:48.258132115Z Found tar.gz based node_modules.
2020-08-19T10:44:48.258154316Z Removing existing modules directory from root...
2020-08-19T10:44:48.260461807Z Extracting modules...
2020-08-19T10:44:48.262765098Z tar (child): node_modules.tar.gz: Cannot open: No such file or directory
2020-08-19T10:44:48.262778299Z tar (child): Error is not recoverable: exiting now
2020-08-19T10:44:48.262970515Z tar: Child returned status 2
2020-08-19T10:44:48.262983816Z tar: Error is not recoverable: exiting now
2020-08-19T10:44:48.290740216Z Done.
2020-08-19T10:44:48.512406278Z npm info it worked if it ends with ok
2020-08-19T10:44:48.512836614Z npm info using npm#6.14.4
2020-08-19T10:44:48.512976126Z npm info using node#v12.16.3
2020-08-19T10:44:48.578204629Z npm info lifecycle adal_appp#0.1.0~prestart: adal_appp#0.1.0
2020-08-19T10:44:48.584464048Z npm info lifecycle adal_appp#0.1.0~start: adal_appp#0.1.0
2020-08-19T10:44:48.589867495Z
2020-08-19T10:44:48.589881796Z > adal_appp#0.1.0 start /home/site/wwwroot
2020-08-19T10:44:48.589887297Z > react-scripts start
2020-08-19T10:44:48.589891697Z
2020-08-19T10:44:48.597331914Z sh: 1: react-scripts: not found
2020-08-19T10:44:48.598224588Z npm info lifecycle adal_appp#0.1.0~start: Failed to exec start script
2020-08-19T10:44:48.599091959Z npm ERR! code ELIFECYCLE
2020-08-19T10:44:48.599182267Z npm ERR! syscall spawn
2020-08-19T10:44:48.599258573Z npm ERR! file sh
2020-08-19T10:44:48.599314678Z npm ERR! errno ENOENT
2020-08-19T10:44:48.600738196Z npm ERR! adal_appp#0.1.0 start: `react-scripts start`
2020-08-19T10:44:48.600749897Z npm ERR! spawn ENOENT
2020-08-19T10:44:48.600754497Z npm ERR!
2020-08-19T10:44:48.600758798Z npm ERR! Failed at the adal_appp#0.1.0 start script.
2020-08-19T10:44:48.600763398Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-08-19T10:44:48.605436585Z npm timing npm Completed in 125ms
2020-08-19T10:44:48.605621800Z
2020-08-19T10:44:48.605672405Z npm ERR! A complete log of this run can be found in:
2020-08-19T10:44:48.605750311Z npm ERR! /root/.npm/_logs/2020-08-19T10_44_48_601Z-debug.log
But the thing is the same application runs perfectly on local with below commands
npm install , npm start.
and just to verify whether the build which generated after npm run build works or not tried running the application from the build directory with below commands
npm install -g serve
then
serve -s build
then application opens up in browser.
After doing some googling found solution. We need to add the below command in start up command in app service configuration for the Linux machines.
pm2 serve /home/site/wwwroot --no-daemon
Steps:
- Go to App Service
- Navigate to Configuration
- Click on General Settings
- add the above command in Start up command, click on save
- then restart the server
From the log it looks like this is not a Node.js application, but a react application. Therefore react-scripts start is something the Azure App Service doesn't know anything about.
When you run a react app on localhost, it is powered by a development server which indeed is a Node.js server, but once you build it for production using npm run build it is nothing but an index.html file powered by a bunch of .js files and stylesheets. It has no web capabilities in itself.
serve on the other hand is a separate story. As per their description at npmjs.com: Assuming you would like to serve a static site, single page application or just a static file (no matter if on your device or on the local network), this package is just the right choice for you.
But this is not an Azure-like approach.
In production however, if you are using Azure, I recommend using Azure Blob Storage v2, which has static site hosting capabilities. Enable static site hosting in the blob storage and deploy the build folder in a container named $web. Ofcourse all of this is automatically done if you are using vscode with the Azure plugin. Assuming you have signed into Azure thru vscode, right-click on the build folder and select deploy to static site, follow the steps and you will be live with your react app.
However, if you do have a Node.js express backend alongside the react app, then you may put the build folder into the Node.js project at the same level as the node_modules folder and use static routing to have both frontend and backend work as a single package. Explicitly define a route to tell express to respond with the index.html file when asked for. Then you can deploy the whole package into an Azure App Service.
const express = require('express');
const path = require('path');
const port = process.env.PORT || 3006;
const app = express();
app.use(express.json())
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json({extended: true}));
app.use(express.static(__dirname + '/build'));
app.get('/', (req, res) => {
res.sendFile(path.join(__dirname + '/build/index.html'))
});
// Then prefix your API endpoints with /api
app.get('/api/user/:id', (req, res) => {
// Code to get user by id
});
app.post('/api/user', (req, res) => {
// Code to save user
});
app.listen(port, () => {
console.log(`App bootstrapped on port ${port}...`);
});
When / is hit, then index.html is served. API calls served as defined with /api/*. I find this mechanism useful many a times.
Good luck.

Failed exitCode=-4071

I am following this guide. Having problem deploying to azure.
https://learn.microsoft.com/en-us/azure/app-service-web/app-service-web-nodejs-sails#step-3-configure-and-deploy-your-sailsjs-app
Full Error
remote: Failed exitCode=-4071, command="D:\Program Files (x86)\nodejs\6.9.1\node.exe" "D:\Program Files (x86)\npm\3.10.8\node_modules\npm\bin\npm-cli.js" install --production
also
remote: npm ERR! EINVAL: invalid argument, rename 'D:\home\site\wwwroot\node_modules\.staging\spdx-license-ids-3f30671f' -> 'D:\home\site\wwwroot\node_modules\sails-hook-grunt\node_modules\grunt-contrib-cssmin\node_modules\maxmin\node_modules\pretty-bytes\node_modules\meow\node_modules\normalize-package-data\node_modules\validate-npm-package-license\node_modules\spdx-correct\node_modules\spdx-license-ids'
Thanks
I do a demo following the tutorials that you mentioned. It works correctly on my side. I used node.js v7.9 locally. If it is possible, please have a try to update the node.js version to latest locally. The following is my details steps.
1.Following the document to install Sails and create a demo project
$npm install sails -g
$sails new test-sails-project
2.go to localhost:1337 to see your brand new homepage
$ cd test-sails-project
$ sails lift
We can check that it works correctly in the local
4.Following the document step by step
a.Add iisnode.yml file with the following code in the root directory
loggingEnabled: true
logDirectory: iisnode
b.set port and hookTimeout in the config/env/production.js
module.exports = {
// Use process.env.port to handle web requests to the default HTTP port
port: process.env.port,
// Increase hooks timout to 30 seconds
// This avoids the Sails.js error documented at https://github.com/balderdashy/sails/issues/2691
hookTimeout: 30000,
...
};
c.hardcode the Node.js version you want to use. In package.json
"engines": {
"node": "6.9.1"
},
5.Create a Azure WebApp on the Azure portal and get the profile.
6.Push the code to the Git remote and check from the Azure portal.

Running AtlasBoard on Azure Web App with iisnode

I´m trying to run AtlasBoard in an Azure Web App, but can´t get it to work. I have created a new board using the "Get started in 30 seconds" steps and the demo board runs fine when I start it locally. It works both by starting it with atlasboard start 3333or if I run node start.
I´ve added the node_modules directory to .gitignore.
I´m using git deployment on Azure and this seems to work fine. The deployment log also shows that the npm modules are installed.
This is the last ouput from the deployment:
Using start-up script start.js from package.json.
Generated web.config.
The iisnode.yml file explicitly sets nodeProcessCommandLine. Automatic node.js version selection is turned off.
Selected npm version 3.5.1
npm WARN Invalid name: "HRMTS AtlasBoard"
npm WARN wwwroot No description
npm WARN wwwroot No repository field.
npm WARN wwwroot No README data
npm WARN wwwroot No license field.
Finished successfully.
However, the app doesn´t seem to start and when I look at the log message in the Kudu console, I get this:
Error: error installing D:\home\site\wwwroot\packages\demo
at process.<anonymous> (D:\Program Files (x86)\iisnode\interceptor.js:73:106)
at emitOne (events.js:96:13)
at process.emit (events.js:188:7)
at process._fatalException (node.js:267:26)
Does anyone have a clue about what´s wrong here?
If you are using the repo of the demo application at https://bitbucket.org/atlassian/atlasboard/src to test on Azure, there several additional modifications we need do to make the test run on Azure Web Apps.
First of all, assume you have successfully deploy the application to Azure, and it failed when start running the application. Then you can leverage Kudu console site or Visual Studio Online extension (refer to the answer of How to install composer on app service? for how to enable extensions of Azure Web Apps) to check the error log at D:\home\site\wwwroot\packages\demo\npm-debug.log.
There are similar errors:
155 error node -v v0.6.20
156 error npm -v 1.1.37
157 error message SSL Error: CERT_UNTRUSTED
It seems that the atlasboard runs command with very low node version on Azure. We can manually modify the dependent scripts to bypass the errors.
If you get error during deployment, you should modify the npm version in package.json before deployment, for example:
"engines": {
"npm": ">2.0.0",
"node": ">=0.10"
},
After deployment:
check and modify the port in the start.js in the root directory:
atlasboard({port: process.env.port||3000 , install: true},
function (err) {
if (err) {
throw err;
}
});
modify the install function in D:\home\site\wwwroot\node_modules\atlasboard\lib\package-dependency-manager.js to use a higher npm version and remove --production param, e.g :
...
var npmCommand = isWindows ? "D:\\Program Files (x86)\\npm\\3.5.1\\npm.cmd" : "npm";
executeCommand(npmCommand, ["install", pathPackageJson], function(err, code){
...
})
Then restart your website.
Any further concern, please feel free to let me know.

Azure Website Deploy Error: install.js: Unable to download msnodesql-0.2.1-v0.10-ia32.msi

Right now, I am trying to set up Node.js website connect to Azure SQL(Not MySQL).
I have created a simple program to get data from Azure mssql database.
On local it works fine.(It retrieves info from Azure MSSQL)
However, when I try to deploy, I get "deployment error".
Here is the gist of error I get.
npm ERR! weird error 1
install.js: Unable to download msnodesql-0.2.1-v0.10-ia32.msi
Failed exitCode=1, command="D:\Program Files (x86)\nodejs\0.10.21\node.exe" "D:\Program Files (x86)\npm\1.3.11\node_modules\npm\bin\npm-cli.js" install --production
An error has occurred during web site deployment.
npm
My package.js is as follows
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.8",
"jade": "*",
"nconf": "~0.6.9"
}
}
Inside, node_modules, there is also mnodesql folder which I downloaded from GitHub[https://github.com/WindowsAzure/node-sqlserver]
I run the following code too.
node-gyp configure
node-gyp build
I would appreciate any advice you can offer.
Thanks.
AFAIK, node-sqlserver needs C++ environment to compile the source code but there's no C++ compiler in Azure Website. What I did is to compile this module on local machine and upload as part of my source code. I covered this scenario at the bottom of my blog http://wblo.gs/dLo.
Hope this helps.

Can't run a specific version of node on openshift

I am following the steps described in this repository but I can't seem to make it work. When I look into my env file the nodejs version is still .6.20
My node js version file is the default one, so the node version .8.9 should be running. Any idea why this is happening?
My marker file:
0.8.9
Debug output when I try to start my application
==> nodejs/logs/node.log <==
npm ERR! node -v v0.6.20
npm ERR! npm -v 1.1.37
npm ERR! code ELIFECYCLE
npm ERR! message application-name#0.0.1 start: `node server.js`
npm ERR! message `sh "-c" "node server.js"` failed with 1
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/lib/openshift/51ba8386e0b8cd2873000002/app-root/runtime/repo/npm- debug.log
npm ERR! not ok code undefined
npm ERR! not ok code 1
Just for the sake of completeness. My package.json file
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "3.2.5",
"mustache": "*",
"request" : "*",
"buildify":"*",
"cheerio" : "*",
"slugs" : "*",
"to-markdown":"*",
"consolidate":"*"
}
}
The app runs locally just fine.
I like this version of the nodejs starter code better: https://github.com/ryanj/nodejs-custom-version-openshift
It contains a newer version of the .openshift application build hooks for nodejs. It will read the Marker file, but also has support for reading directly from your package.json file's engines attribute to compile your Nodejs runtime.
"engines": {
"node": ">= 0.10.0",
"npm": ">= 1.0.0"
},
I'm hoping to get this merged in as the default .openshift folder content for all nodejs apps on OpenShift.
You'll also want to make sure that you are binding to the NEW environment variables: OPENSHIFT_NODEJS_IP and OPENSHIFT_NODEJS_PORT. These were recently renamed.
I usually add something like this to my application code, allowing it to run anywhere:
var ip_addr = process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1';
var port = process.env.OPENSHIFT_NODEJS_PORT || '8080';
OpenShift currently shows you the output from npm start, which may not reveal all of your application's output. For additional debugging info, you could try starting your app manually:
First, stop your app from the command line: rhc app stop APP_NAME
Then, connect to your application gear / container rhc ssh APP_NAME
cd $OPENSHIFT_REPO_DIR
and manually run whatever command is defined within your package.json file's scripts.start attribute.
Hopefully that gives you a bit more visibility into what is going on.
Maybe this will help. There are subtle differences. See also the comments.
https://www.openshift.com/blogs/any-version-of-nodejs-you-want-in-the-cloud-openshift-does-it-paas-style
Did you see anything like this in your "git push" output?
remote: - Checking to see if Node.js version 0.8.9 is installed ...
remote: - Downloading and extracting http://nodejs.org/dist/v0.8.9/node-v0.8.9-linux-x64.tar.gz ...
remote: % Total % Received % Xferd Average Speed Time Time Time Current
remote: Dload Upload Total Spent Left Speed
remote: 100 4578k 100 4578k 0 0 31.4M 0 --:--:-- --:--:-- --:--:-- 33.8M
and towards the bottom of the bottom, something like:
remote: - Using Node.js version 0.8.9, checking app URI ...
remote: - test URI = http://mynode-sannam.rhcloud.com/env
remote: - Version from test URI =
remote:
remote: - Checking to see if Node.js version 0.8.9 is installed ...
I tried the same instructions and it seems to have worked. Check my env here: http://mynode-sannam.rhcloud.com/env
Please redo your steps one more time.
I had the same problem and on the beginning i wasn't able to solve it using source code from https://github.com/ryanj/nodejs-custom-version-openshift, but reading the push output I noticed some permission problems.
So for other people that is having the same issue, just go into:
cd .openshift\action_hooks
and run this command:
git update-index --chmod=+x *
It gives the permissions to run commands that upgrades node version

Resources