javascript - not able to load java script files and bower_components/angular/angular.js -
when run localhost:3000 server , i'm getting these errors in console:
http://localhost:3000/bower_components/angular/angular.js failed load resource: server responded status of 404 (not found)
http://localhost:3000/controller.js failed load resource: server responded status of 404 (not found)
it working if put angular.js script in index.html instead of putting seperately in controller.js , don't know why i'm getting error when use script tags.
the directory diagram this
-files -bower_components -angular -index.html -controller.js -server.js
this index.html file
<!doctype html> <html ng-app="app"> <head> <style> #list { margin-left:320px; font-size: 40px; font-family:verdana; } button { color:yellow;background-color:red;text-align:center;cursor:pointer; -webkit-transition-duration: 0.4s; transition-duration: 0.4s; font-size:40px; padding: 14px 32px; } button:hover { background-color:peachpuff; color:tomato; } </style> </head> <body style="background-color:cyan;"> <div ng-controller="ctrl"> <h1 style="text-align:center;font-family:verdana;">to-do list</h1> <div style="margin-left:300px"> <input type="text" ng-model="task.name" style="background-color:black;color:white;font-size:40px;width:40%"> <button ng-click="addtask()">add</button> <button ng-click="updatetask()">update</button> <button ng-click="clearfield()">clear</button> </div> <ul> <li id="list" ng-repeat="task in todolist"> {{task.name}} <button ng-click="deletetask(task._id)">delete</button> <button ng-click="edittask(task._id)">edit</button> </li> </ul> </div> </body> <script type="text/javascript" src="bower_components/angular/angular.js"></script> <script type="text/javascript" src="controller.js"></script> </html>
this server.js file
var express = require('express'); var app = express(); var mongoose = require('mongoose'); var bodyparser = require('body-parser'); app.use(bodyparser.json()); mongoose.connect("mongodb://localhost/test"); var todoschema = new mongoose.schema ({ name : {type: string, required: true} }); var todomodel = mongoose.model('todolist',todoschema); app.get('/',function(req,res){ res.sendfile("/index.html",{root:__dirname}); }); app.get('/todolist', function (req, res){ todomodel.find(function(err,tasks){ res.json(tasks); }); }); app.post('/todolist', function (req, res) { todomodel.create({name:req.body.name},function(err,task){ res.send('created'); }); }); app.delete('/todolist/:id', function (req, res) { todomodel.remove({_id:req.params.id}, function (err) { res.send(''); }); }); app.get('/todolist/:id', function (req, res) { todomodel.findbyid(req.params.id, function (err, task){ res.json(task); }); }); app.put('/todolist/:id', function (req, res) { todomodel.findbyidandupdate(req.params.id, {name: req.body.name}, function (err, task) { res.json(task); } ); }); app.listen(3000); console.log("server running on port 3000");
in server.js file add following lines , check once.
app.use(express.static(__dirname));
in node js have set registry accessing relative paths.
Comments
Post a Comment