0

I have node server and html file, where the route will be directed by default.

server.js

/**
 * Created by Nutty Programmer on 10/26/2015.
 */
var express = require('express');
var mysql = require('mysql');
var app = express();
var path = require('path');

/*
 * Configure MySQL parameters.
 */
var connection = mysql.createConnection({
    host : "localhost",
    user : "root",
    password : "",
    database : "two_way_demo"
});

connection.connect(function(error){
    if(error)
    {
        console.log("Problem with MySQL"+error);
    }
    else {
        console.log("Connected with Database");
    }
});

app.get('/',function(req,res){
    res.sendfile('index.html');
    //res.sendFile(path.join(__dirname, '/', 'index.html'));
    //res.sendFile('index.html', { root: path.join(__dirname, '/') });
});

app.get('/load',function(req,res){
    connection.query("SELECT * from user_info",function(err,rows){
        if(err)
        {
            console.log("Problem with MySQL"+err);
        }
        else
        {
            res.end(JSON.stringify(rows));
        }
    });
});

app.listen(3000,function(){
   console.log("Start listening on port 3000");
});

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="angular.js"></script>
</head>
<body>
<h1>hello world</h1>
</body>
</html>

When I am trying to add angular.js in html. It gives 404 Not found error.

Header:
Remote Address:[::1]:3000
Request URL:http://localhost:3000/angular.js
Request Method:GET
Status Code:404 Not Found

What should be the current path?

2
  • Are you using Express ? Your angular.js file should be in /public/javascript or similar directory, which is the default directory searched Commented Oct 26, 2015 at 17:18
  • @avrono I am using express, and on project root directory have files: server.js, index.html, angular folder>angular.js Commented Oct 26, 2015 at 17:28

1 Answer 1

3

if you want to serve up static content with express you need to do something like...

app.use(express.static(__dirname + '/../'));

where the arg to express.static is the dir with your static content.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.