Andrey2016-01-09 20:01:50
Andrey, 2016-01-09 20:01:50

404 error when starting the server. What could be the problem?

Here is the code in the books from Osmani's book :

// Module dependencies.
var application_root = __dirname,
    express = require( 'express' ), //Web framework
    bodyParser = require('body-parser'), //Parser for reading request body
    path = require( 'path' ), //Utilities for dealing with file paths
    mongoose = require( 'mongoose' ); //MongoDB integration

//Create server
var app = express();

//Where to serve static content
app.use( express.static( path.join( application_root, 'site') ) );

//Start server
var port = 4711;

app.listen( port, function() {
    console.log( 'Express server listening on port %d in %s mode', port, app.settings.env );

When starting the server with the node server.js command, I get the following message:
Cannot GET /

Here I found a question of a person who encountered this problem.
He was advised to add this code:
app.get('/', function (req, res) {
  res.render('index', {});

But at the same time I get the 500th error.
What could be an ambush?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Andrey Dyrkov, 2016-01-09

The path to the statics is incorrect, you may not have an index file. Now you have express looking for an index file in the root of the application, do you have it there?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question