Issue on Deploying Node.js & Socket.IO App to Nodejitsu - node.js

I am new at Node.js, Socket.IO, and Nodejitsu. I am also running Ubuntu on my machine. After Googling for free hoisting supports for Node.js and Socket.IO, I find the Nodejitsu hosting platform. They say it is easy to deploy an app but I find it a little complicated. Here is the Process which I followed.
After setting up my account with Nodejitsu I ran:
sudo npm install jitsu -g
sudo jitsu install socket.io
And I tried to deploy an app by using:
jitsu deploy
but I got two warnings on cmd line as:
warn: There is no package.json file in /home/ben
warn: Creating package.json at /home/ben/package.json
and the the jitsu is prompting as:
prompt: Application name: (ben)
prompt: Subdomain name: (cand-ben)
prompt: scripts.start:
First off, I don't understand what those two warnings are for? Should I create a package.json file there? I also tried to start a script like this in command line after prompt: scripts.start:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('hello, i know nodejitsu\n');
}).listen(8080);
but I am getting this error messages
prompt: scripts.start: var http = require('http');
error: Invalid input for scripts.start
error: Start script was not found in /home/ben
prompt: scripts.start: http.createServer(function (req, res) {
error: Invalid input for scripts.start
error: Start script was not found in /home/ben
prompt: scripts.start: res.writeHead(200, {'Content-Type': 'text/plain'});
error: Invalid input for scripts.start
error: Start script was not found in /home/ben
prompt: scripts.start: res.end('hello, i know nodejitsu\n');
error: Invalid input for scripts.start
error: Start script was not found in /home/ben
prompt: scripts.start: }).listen(8080);
Can you please let me know how should I pass the script into the command prompt? How should I create the package.json? is there a any clear tutorial illustrating these thing?
Thanks
Error After adding the package.json from Peter site.
warn: About to write /home/ben/package.json
data:
data: {
data: engines: { node: '0.8.x' },
data: name: 'ben',
data: scripts: { start: '' },
data: subdomain: 'candente-ben',
data: version: '0.0.0'
data: }
data:
prompt: Is this ok?: (yes)
info: Analyzing application dependencies in
WARN package.json ben#0.0.0 No repository field.
WARN package.json ben#0.0.0 No readme data.
info: Checking app availability ben
info: Checking app availability ben
info: Creating app ben
info: Creating app ben
error: Error creating ben
error: Nodejitsu Error (500): Internal Server Error
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
warn: Error returned from Nodejitsu
error: Error: App name / subdomain combination is not available
error: at module.exports (/root/nodejitsu/lib/nodejitsu/resources/app/controller/available.js:27:17)
error: at Resource._request (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:184:13)
error: at Function.Resource.runAfterHooks (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:93:12)
error: at Resource._request (/root/nodejitsu/node_modules/resourceful/lib/resourceful/resource.js:179:14)
error: at Couchdb.view (/root/nodejitsu/node_modules/resourceful/lib/resourceful/engines/couchdb/index.js:143:5)
error: at Request._onResponse [as _callback] (/root/nodejitsu/node_modules/resourceful/node_modules/cradle/lib/cradle.js:233:9)
error: at Request.init.self.callback (/root/nodejitsu/node_modules/request/main.js:120:22)
error: at Request.EventEmitter.emit (events.js:99:17)
error: at Request.<anonymous> (/root/nodejitsu/node_modules/request/main.js:555:16)
error: at Request.EventEmitter.emit (events.js:96:17)
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support#nodejitsu.com>
help:
help: Copy and paste this output to a gist (http://gist.github.com/)
info: Nodejitsu not ok

First of I didn't understand what those two warnings are for? Should I create a package.json file there?
Yes. A package.json file is required for nodejitsu deployment to work. It describes the environment your application needs in order to operate.
I also tried to start a script like this in command line after prompt: scripts.start:
The scripts.start cannot be javascript code, it must be a simple shell command. Take that javascript code and save it in a file called server.js and then make your scripts.start command be node server.js.
Here's Nodejitsu's interactive guide to the package.json file. Of course the official npm docs on package.json are a must-read. And here is an open-source app I wrote that is deployed on nodejitsu if you want to reference that. The basic scripts.start property will need to be along the lines of:
"scripts": {"start": "node server.js"}
Update
So you are probably trying too many things at once here, without spending enough time on the basics to stay out of trouble. Do not skip any of these steps. You will learn and comprehend in the process and you'll be able to understand future errors on your own.
First, get your app running locally with a manual command like node server.js.
Second, the the command npm start working locally by getting your package.json correct.
Third, then work on making it work on nodejitsu.

Related

"Process out of memory" error after installing node from source

I'm trying to install NodeJS on shared hosting. I downloaded the source from
https://nodejs.org/en/download/
and followed the usual install procedure with ./config --prefix="$HOME/local".
It compiles without error. However, when I try to run it, I get the following error:
installing /kunden/homepages/32/d690510543/htdocs/local/include/node/zconf.h
installing /kunden/homepages/32/d690510543/htdocs/local/include/node/zlib.h
(uiserver):xxxxxxxx:~/node-v8.11.2$ which node
/kunden/homepages/32/d690510543/htdocs/local/bin/node
(uiserver):xxxxxxxx:~/node-v8.11.2$ node
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
Illegal instruction
However, I can get the version
$ node -v
v8.11.2
and help.
Nevertheless, I can't run a script
(uiserver):xxxxxxxx:~$ cat hello.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
(uiserver):xxxxxxxx:~$ node hello.js
#
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
#
Illegal instruction
Nor can I enter the REPL:
(uiserver):xxxxxxxx:~$ node -i
#
Fatal error in , line 0
API fatal error handler returned after process out of memory
#
Illegal instruction
I had the same issue and what i realized was that it was only occuring when i use mlab sandbox mongo db.Initially everything was ok even with mlab mongo db but all over sudden i the error started appearing .I changed to locally installed mongodb and all was well,i deleted my mlab mongo db collections and changed back to mlab,all was well again.I guess the issue is with mlab free tier limitations
When I execute my Vue.js project with command:
npm run dev
in webstorm console, the console output:
# Fatal error in , line 0
# API fatal error handler returned after process out of memory
Then when I restart use command:
npm run dev
webstorm crashes, I restart webstorm and use command:
npm run dev
a second time, and it works. So I think it is because that my computer memory is not enough when webstorm starts too many child processes.
Had the same issue (and afaik the same hosting provider). However, installing node through nvm, like described e.g. at https://stackoverflow.com/a/33857377/1680728 did solve the issue for me. I do not know whether its some environment setting or has to do with the fetched binaries/version.
So, I cannot solve the "Process out of memory" error, but I guess the real problem was to have any nodejs version running on a shared host.
I had the same issue and I close my webstorme and try again

Need help getting simple node.js express to run

I'm trying a simple sample of node express that I copied from online. The script is below which I think is pretty standard.
var http = require('http');
http.createServer(function(request, response)){
response.writeHead(200);
response.write("hello");
response.end();
}).listen(8080);
console.log('listening on port 8080...');
I used the bash on ubuntu on windows command as follows:
npm init
node SampleServer.js (the name of my file)
When I do this, I expect some response from the command line. But when I enter the "node SamplerServer.js" command, nothing happens. When I direct the browser to port 8080, I get an error message as well.
I'm using nodeclipse and the installing that on my machine was pretty complicated. Prior to any of the steps above, I created an express project in eclipse ide. It seems to perform a lot of pre steps but in the end, I think I'm getting some of the error messages below. I'm mentioning this because I'm thinking perhaps I installed one of the modules wrong.
enter image description here
Start with simple stuff...
Use express-generator to create simple app by the following command
1-> npm install -g express-generator with root or Admin access
2-> Run express demoapp.
3-> Navigate to demoapp
4-> Do npm install
5-> Run from command with npm start: it run by default on http://localhost:3000
Hit that URL from Browser

How to install node.js and create project in Eclipse

The steps I've tried:
1.(OK) install node from official website: https://nodejs.org/en/download/
Result: I'm able to open cmd(in any location, type node then use commands like "console.log" and it prints my messages)
2.(Failure) install express using npm install -g express from cmd gives me an error(picture attached
3.(OK) I've succeed installing express using the following command npm install express (without -g)
4.(OK) Writing a simple Hello World program works. Javascript file:
var http = require('http');
// Configure our HTTP server to respond with Hello World to all requests.
var server = http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("Hello World\n");
});
// Listen on port 8000, IP defaults to 127.0.0.1
server.listen(8000);
// Put a friendly message on the terminal
console.log("Server running at http://127.0.0.1:8000/");
5.(Failure) However, I wanna run a bigger project, where besides one js file, I also have an index.html file. If I move both files to node installation directory, everything works. But I wanna be able to keep my projects somewhere else. If I try to run with node C:\Users\marius\Downloads\chat-example-master\indes.js I get the error: Cannot find module express. Thus it seems that when I installed express without "-g" I got it working only in node directory.(let me know if you have any doubt).
6.(Failure) When creating a Node.js project from Eclipse, I choose empty project, no template, then add a single and simple js file(the one with Hello World), right click on project name -> run as -> run Configuration -> Node Application -> New -> add my .js file -> Run. I get the following error:
Exception occurred executing command line.(steps from http://techprd.com/how-to-setup-node-js-project-in-eclipse/)
Cannot run program "node" (in directory "C:\Users\marius\workspace\FirstNodeProject"): CreateProcess error=2, The system cannot find the file specified
To recap: What I want is to be able to run node projects located anywhere with "node" in cmd and to create node.js and express project and run them from Eclipse.
Please let me know if you need more information.
Just to let others know if they come across this issue. I can run express apps from anywhere but in the root folder of every app I have to npm install express.
In Eclipse all you need to do is: Window->Preferences->Nodeclipse->uncheck "find .Node on PATH" and insert into Node.js path input your node.exe location (in my case: C:\Program Files\nodejs\node.exe)

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.

Nodejitsu while while starting node.js app

I am very new to node.js, I just followed the steps to create a simple node.js application. Here it is on github
I ran the command jitsu deploy from the terminal to deploy it on nodejitsu, however I got this error right here, please any help on what could be wrong with code files?
Here is the code on git hub
Here is the error that is appearing:
prompt: Is this ok?: (yes) yes
info: Creating snapshot 0.0.0-5
info Uploading: [=============================] 100%
info: Updating app test
info: Activating snapshot 0.0.0-5 for test
info: Starting app test
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Error spawning drone
error: Script took too long to listen on a socket
error:
error: This type of error is usually a user error.
error: Error output from Haibu:
error:
error: Error: Error spawning drone
error: at Object.onTimeout [as _onTimeout] (/root/haibu-orchestra/node_mod
ules/haibu/lib/haibu/core/spawner.js:396:15)
error: at Timer.list.ontimeout (timers.js:101:19)
help: For help with this error contact Nodejitsu Support:
help: webchat: <http://webchat.nodejitsu.com/>
help: irc: <irc://chat.freenode.net/#nodejitsu>
help: email: <support#nodejitsu.com>
You're server.js is exporting a function, but that doesn't get run. Just the body of your start function as top-level code directly inside the server.js module so that it executes when nodejitsu starts your application.
Nodejitsu is very picky about how quick your deployments listen on the system. There is a certain time frame between the start of deployment and end of deployment before your deployment is considered a failure. When it doesn't listen on a port for so long, it ends up giving you this error.
Rather than using your current start function, why don't you try creating your HTTP socket in index.js and then passing it into your start function as well, since you're already passing routes and handle to it?
For example, in index.js:
var http = require('http'),
server = http.createServer().listen(8080);
start(server, router.route, handle);
Then, rather than using http.createServer(onRequest).listen(8080) in your server.js file, you can use something like:
var start = function (server, route, handle) {
function onRequest(request, response) {
/* Your request stuff here */
}
server.on('request', onRequest);
};
This would most likely solve the whole problem.

Resources