I have set up a Janusgraph Docker instance (janusgraph/janusgraph:latest - Lucene/BerkeleyDB/Tinkerpop/Gremlin Server) in a Linux VM in my datacentre. On the same VM and on my laptop, I've run the same JanusGraph Docker image but run the gremlin console (adjusting conf/remote.yaml to point to the gremlin server) and successfully imported air-routes.graphml into the server instance. I can also successfully query the air-routes data with some simple traversals.
In summary: I'm confident that the server is running, has data, can be remotely connected and respond to traversals.
I have been stuck on the next step for a long, long time:
I have created a basic Node express stub:
var createError = require('http-errors');
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var gremlin = require('gremlin');
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const traversal = gremlin.process.AnonymousTraversalSource.traversal;
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
const g = traversal().withRemote(
new DriverRemoteConnection('ws://mygremlinserverhost:8182/gremlin'));
This fails with the following:
npm run start
greg:air-routes/ $ npm run start [21:07:39]
Debugger attached.
> air-routes#0.0.0 start
> node ./bin/www
Debugger attached.
Waiting for the debugger to disconnect...
node:internal/process/promises:227
triggerUncaughtException(err, true /* fromPromise */);
^
Error: connect ECONNREFUSED <The IP of the VM>:8182
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1138:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '<The IP of the VM>',
port: 8182
}
Waiting for the debugger to disconnect...
greg:air-routes/ $
(Also, I don't understand this notification, or whether it's the cause (or effect) of the inability to connect - What am I doing wrong or not doing. Please assume an idiot novice who needs the basics explaining. Thanks, I think? ;o) )
node:internal/process/promises:227
triggerUncaughtException(err, true /* fromPromise */);
^
I believe the inability to connect was because I had not specified a docker port mapping to the OS port on the server's docker run command.
Should have been (with the port mapping switch -p)
docker run --name janusgraph-default -p 8182:8182 --volume /myLocalDir/gremlin:/dataImports janusgraph/janusgraph:latest
Related
I've decided to make the jump from building my websites with slim, php and twig to using node.js and express.
To limit the shock of changing my whole process I want to keep using slim as the template engine instead of the default jade.
I have tried to change the code to change the render engine over to twig but now I am getting the following error message. Does anyone know what I am doing wrong? I am at a loss as to why it is not working. Any help would be very helpful.
Error message:
Error: Failed to lookup view "error" in views directory "/var/www/html/SocialTrackers/app/views"
at Function.render (/var/www/html/SocialTrackers/app/node_modules/express/lib/application.js:580:17)
at ServerResponse.render (/var/www/html/SocialTrackers/app/node_modules/express/lib/response.js:1008:7)
at /var/www/html/SocialTrackers/app/app.js:38:7
at Layer.handle_error (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/layer.js:71:5)
at trim_prefix (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/index.js:315:13)
at /var/www/html/SocialTrackers/app/node_modules/express/lib/router/index.js:284:7
at Function.process_params (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/index.js:335:12)
at next (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/index.js:275:10)
at Layer.handle_error (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/layer.js:67:12)
at trim_prefix (/var/www/html/SocialTrackers/app/node_modules/express/lib/router/index.js:315:13)
This is the code I am currently running. Other than changes to shift over the using twig as the render engine, I have made no other changes to the initial express install.
app.js
var createError = require('http-errors');
var twig = require("twig");
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, './views'));
app.set('view engine', 'twig');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/bootstrap', express.static(__dirname + '/node_modules/bootstrap/dist/'))
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
next(createError(404));
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Additionally, I am the following file structure (default express)
app
--bin
--node_modules
--public
--routes
----index.js
----users.js
--views
----error.twig
----index.twig
----landingpage.twig
--app.js
Took me a few days to figure this one out.
As I said I'm new to Nodejs and express so I believe I made a very rookie mistake. I thought I would post the solution incase anyone else has this issue.
I was running the node server on a ec2 instance. While I was updating the code it turns out I had to restart the node server as well.
I'm using pm2 to keep the server running all the time so for me the solution was to run the following command.
pm2 restart [namespace of server]
Note: for me, I never gave the server a namespace so it was simply 'default'. If you don't know the namespace you can find it by running 'pm2 list'
pm2 restart default
const express = require("express");
const path = require("path");
var hbs = require("express-handlebars");
const morgan = require("morgan");
const middlewares = require("./middlewares/middlewares");
const PORT = process.env.PORT || 3002;
var app = express();
// setup static file service
app.use(express.static(path.join(__dirname, "static")));
//Setup app port
app.set("port", process.env.PORT || PORT);
// setup handlebars and the view engine for res.render calls
app.set("view engine", "html");
app.engine(
"html",
hbs({
extname: "html",
defaultView: "default",
layoutsDir: __dirname + "/views/layouts/",
partialsDir: __dirname + "/views/partials/"
})
);
app.get("/", (req, res) => {
res.send("Hello world");
});
app.use(morgan("common"));
app.use(middlewares.errorHandler);
app.use(middlewares.ignoreFavicon);
app.use(middlewares.notFound);
var server = app.listen(app.get("port"), () =>
console.log(`Server started...Listening on port: ${PORT}`)
);
This is my basic server setup. Whenever I request a route I get the following errors in my console. I had to add middleware ignoring this route as well. "GET /favicon.ico HTTP/1.1"
Uncaught TypeError: Cannot convert undefined or null to object
at Function.keys ()
at contentscript.bundle.js:72
at S.Object.isExtensible.Object.isExtensible.e.___hb.e.___hb (contentscript.bundle.js:29)
[Honeybadger] Unable to send error report: no API key has been configured.
is there more of a stack trace? Also, when you say "console", do you mean in the Node console, or in the browser console? It looks like the log message is from our client-side JavaScript package, which I would expect in the browser. If you're catching errors in your Node application, you should use our Node.js package.
In honeybadger.js, ___hb can sometimes appear in stack traces because the function was wrapped by our library, but the error is often still in your project code. I would suggest configuring Honeybadger with an API key if you're trying to diagnose errors in production.
Related docs:
https://docs.honeybadger.io/lib/javascript/index.html
https://docs.honeybadger.io/lib/node.html
I have a pretty simple nodejs project that uses express. When I start this project locally I have noticed that something is calling a POST to /inform about every 30 seconds. I'd like to know what's calling inform and what the purpose is.
I'm new to node. Is this normal? I haven't implemented a route for this call so it causes a 404.
Here's my main app:
const createError = require('http-errors');
const express = require('express');
const path = require('path');
const cookieParser = require('cookie-parser');
const logger = require('morgan');
const fileUpload = require('express-fileupload');
const app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(fileUpload());
// routes
const indexRouter = require('./routes/index');
const usersRouter = require('./routes/users');
app.use('/', indexRouter);
app.use('/users', usersRouter);
// catch 404 and forward to error handler
app.use((req, res, next) => {
console.log(req)
next(createError(404));
});
// error handler
app.use((err, req, res) => {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
In my console, I see this about every 30 seconds:
POST /inform 404 14.002 ms - 2158
POST /inform 404 13.910 ms - 2158
POST /inform 404 31.536 ms - 2158
EDIT:
Thank you for the comments. I changed my express port to 8000 and it no longer happens. So something on my local machine is looping and posting to localhost:8080/inform. I'll have to trace this down.
I have a Ubiquity Unify network stack at home. After running (and stopping) the Unifi Controller on my laptop, all my Unify devices continue to send a POST <laptop IP>:8080/inform.
My own application was getting its logged filled up with the same unknown route: "/inform" error.
Solutions:
Choose a different port
Bind your application to 'localhost' instead of '0.0.0.0'
Get a dedicated controller device, like a Raspberry Pi or Unifi Cloud Key
This could be pretty much any application on your PC or even other systems in your local network, if you are listening on public addresses.
You could implement the route to see if the request header/body give any hint as to where this is coming from.
It may also be possible for external software such as Wireshark to monitor network calls to localhost, including their source.
Otherwise use a different port where no one is sending periodic pings to.
I had a perfectly running nodejs server on an EC2 instance of Amazon AWS. By mistake, I missed a couple of payments and the service was halted. When I paid and brought the account up to date, I found the server was back in place and was already running.
However, since then, my very first request has started returning the "getaddrinfo ENOTFOUND" error and am not able to check any other request either. This is weird, since the first line in the code to check the health of the server (refer to index.html below) return the desired "All Ok" result. But the subsequent requests gives the ENOTFOUND error. Any help in this will be very much appreciated.
FYI, I have tried stopping and restarting the server, didn't help.
Here is the code of the base file:
require('newrelic');
var express = require('express'),
bodyParser = require('body-parser'),
oauthserver = require('oauth2-server');
var multer = require('multer');
var upload = multer({ dest: '../uploads/' });
var controllernew = require('./controllers/controllernew');
var app = express();
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
/***************************************************************
********FOLLOWING REQUEST RETURNS ALL OK AS DESIRED*************
****************************************************************/
app.get('/index.html', controllernew.index);
app.oauth = oauthserver({
model: require('./models/modeloauth'),
grants: ['password'],
debug: true,
accessTokenLifetime: 31536000
});
/******************************************************************
*******GETTING ENOTFOUND ERROR FOR THE FOLLOWING REQUEST***********
*******************************************************************/
app.get('/userOTP/:userid/username/:username', controllernew.getUserOTP);
app.all('/oauth/token', app.oauth.grant());
app.all('*', app.oauth.authorise());
app.use(app.oauth.errorHandler());
app.post('/uploadimagenew', upload.single('upload'), function(req, res) {
var controllernew = require('./controllers/controllernew');
controllernew.createImage2(req, res, function(){
console.log(req.file);
console.log(req.body.csvlistevents);
var strArray = req.body.csvlistevents.split("|");
console.log(strArray[3]);
})
});
routes = require("./routes/items")();
app.use(routes);
var server = app.listen(8080, function(){
console.log('server started at ' + server.address().port);
});
I am running a node.js server developed using express and it is working perfectly. I am trying to secure it using https module. I generated self-signed certificate and key using openssl, but getting the below error from firefox while trying to connect. IE is also not loading the secure page.
Secure Connection Failed
An error occurred during a connection to localhost:3001. Cannot
communicate securely with peer: no common encryption algorithm(s).
(Error code: ssl_error_no_cypher_overlap)
The page you are trying to view cannot be shown because the
authenticity of the received data could not be verified. Please
contact the web site owners to inform them of this problem.
I created the key and certificate using the below commands:
>> openssl genrsa 1024 > key.pem
>> openssl req -x509 -new -key key.pem > key-cert.pem
I am using firefox 39.0, node 0.12.4, express 4.13.1, openssl 0.9.81 and working in windows server 2008 R2 Enterprise.
This is my code. server.js is the starting point: node server.js
server.js:
var http = require('http');
var https = require('https');
var fs = require('fs');
var app = require('./app');
var credentials = {
key: fs.readFileSync('./certificate/key.pem'),
cert: fs.readFileSync('./certificate/key-cert.pem')
};
http.createServer(app).listen(3000);
https.createServer(credentials, app).listen(3001);
app.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var register = require('./routes/register');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
//app.get("/", login.form);
app.get("/register", register.form);
app.post("/register", register.submit);
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handlers
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
});
});
module.exports = app;
I am trying to access the application using:
https://localhost:3001/register
I am stuck in this. Please help me with a solution.
I am so embarrassed. It was my own mistake while creating the certificate file. I forgot to set OPENSSL_CONF variable with openssl.cnf path and the certificate file was created as blank. This was causing the whole issue. We can set the variable in command prompt for current session or in user level in environment variable settings.
set OPENSSL_CONF=c:/<your .cnf location>/openssl.cnf
This was my fault for not checking if Express.js was passed the correct options dictionary in the first place.
I got a sketch of my Express.js code configured to work with HTTPS from another developer who suggested that I should test it. I started testing and got the SSL_ERROR_NO_CYPHER_OVERLAP error in Firefox. I was trying all kinds of tricks: choosing different ciphers, double-checking the certificates, and so on but the SSL_ERROR_NO_CYPHER_OVERLAP was still the same.
It turned out that the options variable with the keys:
const options = {
key: fs.readFileSync("somekey.key"),
cert: fs.readFileSync("somekey.crt"),
ciphers: "DEFAULT:!SSLv2:!RC4:!EXPORT:!LOW:!MEDIUM:!SHA1"
};
was not passed to the following line correctly:
https.createServer(options, app).listen(...
So the Express.js was not using the information about key/cert at all!