0

As a part of angular.js course, i downloaded and installed node.js, inserted server.js file in main folder with following content :

var connect = require('connect');

connect.createServer(
    connect.static("../angularjs")
).listen(5000);

and then tried to run server by cli, but im getting error in cli:

TypeError: Object function createServer() {
  function app(req, res, next){ app.handle(req, res, next); }
  merge(app, proto);
  merge(app, EventEmitter.prototype);
  app.route = '/';
  app.stack = [];
  return app;
} has no method 'static'
    at Object.<anonymous> (C:\Program Files (x86)\nodejs\server.js:4:19)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
  • 1
    possible duplicate of [Installing a Web Server for Node.js](http://stackoverflow.com/questions/25064040/installing-a-web-server-for-node-js) – mscdex Jul 31 '14 at 17:39

2 Answers2

0

try:

var connect = require('connect');
var serveStatic = require('serve-static'); 
var app = connect(); 

app.use(serveStatic('angularjs')); 

app.listen(5000);

Should work for you!

EDIT: With Connect 3.0 .static() is moved to a separate package called serve-static. So you'll have to install that before running this code.

Cariah
  • 41
  • 4
-1

Edit: THis is for an older version of Node and therefore doesn't answer the question. See the comments below.

To use connect, you need to setup the environment, and then create the server

var connect = require('connect');
car app = connect();
app.static("../angularjs");
connect.createServer(app).listen(5000);

You may also be able to do it the brief way that you have by:

connect.createServer(
    connect().static("../angularjs")
).listen(5000);
BraveFoot
  • 116
  • 2
  • Did you even read his error? His problem is explicitly created by your second snippet of code. Your first snippet would generate the same error for him too. – Avery Jul 31 '14 at 17:45
  • You're right. I was using an old version of Node and Connect. This answer explains what to do with the newer versions of Node http://stackoverflow.com/questions/16333790/node-js-quick-file-server-static-files-over-http/24575241#24575241 – BraveFoot Jul 31 '14 at 17:59
  • Seems that server is running but when im trying to open my test page i get "Cannot GET /test.html " in broswer – user3561092 Jul 31 '14 at 18:07