nodejs / node-v0.x-archive

Moved to https://github.com/nodejs/node

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cannot display image in localhost

jenevaL opened this issue · comments

I'm using neo4j in node js, and im trying to display an image to my web page. This is my code:

var express = require ('express');
var request = require ('request');
var path = require('path');
var fs = require('fs');
var logger = require('morgan');
var bodyParser = require('body-parser');
var neo4j = require("neo4j-driver").v1;

var app = express();

//var txtUrl = "http://127.0.0.1:7474/db/data/transaction/commit";

//View Engine
app.set('port', process.env.PORT || 3000);
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));

var neo4jv1 = neo4j.v1;
var driver = neo4j.driver('bolt://127.0.0.1', neo4j.auth.basic('neo4j', 'neo4j14'));

var session = driver.session();
app.get('/', function(req, res){

session
.run("MATCH (n:Snackhouse) RETURN n LIMIT 25")
.then(function(result){
var snackhouseArr = [];
result.records.forEach(function(record){
snackhouseArr.push({
id: record._fields[0].identity.low,
name: record._fields[0].properties.name,
location: record._fields[0].properties.location
});
});

session
  .run('MATCH(n:SnackStore) RETURN n LIMIT 25')
  .then(function(result2){
      var snackstoreArr = [];
      result2.records.forEach(function(record){
        snackstoreArr.push({
          id: record._fields[0].identity.low,
          name: record._fields[0].properties.name,
          location: record._fields[0].properties.location
        });
      });
      res.render('index',{
        snackhouses: snackhouseArr,
        snackstores: snackstoreArr
      });
  })
.catch(function(error) {
 console.log(error);

});

});
});

app.post('/snackhouse/add', function(req, res){
var name = req.body.name;
var location = req.body.location;

session
.run('CREATE(n:Snackhouse {name:{nameParam}, location:{locationParam}}) RETURN n.name', {nameParam:name, locationParam:location})
.then(function(result){
res.redirect('/');
session.close();
})
.catch(function(err){
console.log(err);
});
res.redirect('/');
});

app.listen(3000);
console.log('Server Started on port 3000');

module.exports = app;

<title> HOME </title>
<style>

body {

background: #6699ff;
margin: 0;
padding: 0;
border: 0;
font-size: 100%;
font: inherit;
vertical-align: baseline;
}
.container {
position: relative;
margin: 0 auto;
width: 94%;
max-width: 1100px;
font-family: helvetica, sans-serif;
}
.content {
position: relative;
padding-top: 80px;
}
.content p {
margin-bottom: 10px;
}
#header {
z-index: 2;
position: fixed;
width: 100%;
height: 60px;
line-height: 60px;
background: #222;
color: white;
}
#header h1 {
top: 0px;
margin: 0px;
text-transform: uppercase;
font-size: 1.2em;
}
#nav {
position: absolute;
right: 0;
top: -15px;
height: 60px;
}
#nav ul li {
float: left;
list-style: none;
}
#nav ul li a {
display: block;
color: white;
text-decoration: none;
padding: 0 10px;
}

</style> 

Header Demo

  • Home
  • About
  • Services
  • History
  • Contact
  •          <textarea style="width:200px; height:25px;">search here</textarea>
            
            </right>
    
          </ul>
    
    
        </nav>
      </div>
    </header>
    <div class="content">
      <div class="container">
    
      <img src="C:/neo4j/views/img1.JPG" alt="shigatsu" height="142" width="142">
      
    
        <p>
          Lorem ipsum dolor sit amet, consectetur adipiscing
          elit, sed do eiusmod tempor incididunt ut labore et
          dolore magna aliqua. Ut enim ad minim veniam, quis
          nostrud exercitation ullamco laboris nisi ut aliquip ex
          ea commodo consequat. Duis aute irure dolor in
          reprehenderit in voluptate velit esse cillum dolore eu
          fugiat nulla pariatur. Excepteur sint occaecat
          cupidatat non proident, sunt in culpa qui officia
          deserunt mollit anim id est laborum.
        </p>
        <p>
          Nulla efficitur pharetra leo. In convallis lobortis
          nisl, ut pretium purus aliquam eget. Maecenas
          vestibulum venenatis eros, a volutpat mi malesuada eu.
          Cum sociis natoque penatibus et magnis dis parturient
          montes, nascetur ridiculus mus. Nam mollis vitae eros
          quis congue. Ut eget massa semper, cursus ligula et,
          euismod lacus. Sed neque metus, tristique eget
          scelerisque vitae, luctus at metus. Proin vel
          ullamcorper arcu. Praesent dapibus eleifend turpis et
          euismod. Sed tincidunt lobortis erat, nec elementum
          libero molestie sed. Phasellus eget tristique lorem.
        </p>
        <p>
          Maecenas dictum molestie nisi, eu ornare mauris posuere
          a. Proin tempus est ligula, ut varius risus faucibus
          nec. Morbi ultrices leo et vulputate facilisis. Nunc
          congue, leo a facilisis dictum, metus neque tempus
          arcu, ac aliquet nulla mi a felis. Maecenas quis
          euismod velit. Curabitur dapibus ipsum vitae
          ullamcorper auctor. Nullam nec ultricies urna.
          Curabitur lacinia nec ipsum a condimentum. Quisque
          lacinia faucibus augue, sed efficitur enim mollis eget.
          In et metus non ante interdum varius nec in sem.
        </p>
      </div>
    </div>
    
    Snackhouse Name

    Location


    Snackhouse

      <%snackhouses.forEach(function(snackhouse){ %>
    • <%=snackhouse.name%>
    • <% }) %>

    Snack Stores

      <%snackstores.forEach(function(snackstore){ %>
    • <%=snackstore.name%>
    • <% }) %>

    however when I try to run it, the image doesnt display,

    shigatsu

    but when i try to run it here: file:///C:/neo4j/views/index.ejs.html
    the image is dsplayed but my neo4j query cannot be read:

    shigatsul

    what could be the problem with this?

This is not a node.js specific question. Please use stackoverfow.com or similar