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.
Related
I have been trying to connect database locally to mongodb using nodejs but there are some errors i'm facing some errors while doing that.
In my main folder there is only one connection file named as db.js and other files are package.json and node_modules. This is error I got after running the node db.js at particular location I have installed mongoose also using npm command.
and after using the command node --trace-deprecation I got the following error log.
Here's the code of db.js:-
const mongoose=require('mongoose');
mongoose.connect('mongodb://localhost:27017').then(()=>{
console.log(`conncn established!!\n`);
}).catch((err)=>{
console.log('no connection',err);
})
// module.exports=mongoose;
// "mongodb://localhost:27017/Blogs_db -->it is the connection string for Blogs_db tried to but this //string also but it is not working
I have checked whether my server is running or not and tried to make the new folder and to follow the process again but it still shows the connection error
Go the answer and it is simple just to replace the local host in the connection string with 0.0.0.0 and it worked[Heres the output after replacing the localhost in above code with 0.0.0.0]
I've started the Realm-provided realm-electron-advanced-quickstart found here.
Everything works fine when running in dev, but when I package this with electron-builder, the app does not work. I moved createWindow() to the top of the app.whenReady() function so I could see the debugger, and it showed the following message:
Failed to open realm: Error: illegal operation on a directory
at run (renderer.js:26)
at renderer.js:39
Line 26 is
const realm = new Realm(config);
I suspect this is some sort of path/permissions issue with the .realm file.
In main.js, I changed the path in the realm config to
path.join(app.getPath("home"),"my.realm")
But I could not do so on renderer.js.
I would appreciate any ideas or examples of how this has been implemented before.
I'm running Node v14.15.4.
How to handle the error: Error: getaddrinfo ENOTFOUND unexistantwebsite.com with the node package Websocket(Ws) without making the app crashing ?
I just tryed to create a websocket connect on an non-existant website and that make all the app crashing :
var ws = new WebSocket('wss://unexistantwebsite.com/', {
binaryType: "arraybuffer"
});
I tried many way to handle the error but nothing works.
Surround with try catch: KO
Add .catch on the constructor end: KO (even invalid that's normal I suppose)
I just want to handle the error avoiding the app to crash.
I am creating a progressive web application (pwa) and try to register service worker to test offline feature. The folder structure is like below:
-- views
-- index.pug
-- sw.js
-- public
-- js
-- main.js
-- index.js
index.js file is server file, main.js is the file that being link in each .pug file. I embedded the service worker register code in, the code is like following
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('./sw.js').then(function(registration) {
// Registration was successful
console.log('Service Worker registration successful with scope: ', registration.scope);
// console.log('Service Worker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
The 404 error keeps pop up in localhost also the deployed URL which I have no clue why, how to solve this?
ServiceWorker registration failed: TypeError: Failed to register a ServiceWorker: A bad HTTP response code (404) was received when fetching the script.
Thanks
Solutions (UPDATE) -
Include app.use('/', routes) ,or wherever the service-worker file at into index.js file.
you could use the full url path for the registration for example:
navigator.serviceWorker.register('ScriptsFolder/subFolder/sw.js')
The only way I have found to solve the TypeError issue when starting a nodejs service worker is to put the service worker script in the root directory of your application, in my case the root of my Amazon EC2 web server.
Wish the error message was more descriptive, TypeError is not terribly helpful. But this fix worked for me.
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.