开发者

How to I load a javascript file using express and node.js?

开发者 https://www.devze.com 2023-01-21 05:27 出处:网络
I\'m trying to figure out how to load a simple javascript client-side library while using node.js and express.Any ideas?See below.

I'm trying to figure out how to load a simple javascript client-side library while using node.js and express. Any ideas? See below.

HAML:

%script{type: 'text/javascript', src: '/jquery-1.4.3.js'}
%script{type: 'text/javascript', src: '/client.js'}

app.js:

app.get('/*.js', function(req, res) {
  res.render(req.params + '.js', { layout: false} );
});

Error:

Error: Cannot find module 'js' at loadModule (node.js:275:15) at require (node.js:411:14) at ServerResponse.render (/usr/local/lib/node/.npm/express/1.0.0rc4/package/lib/express/view.js:289:46) at Object. (/Users/seanbollin/nodemud/app.js:18:7) at pass (/usr/local/lib/node/.npm/connect/0.2.6/package/lib/connect/middleware/router.j开发者_运维百科s:72:27) at Object.router [as handle] (/usr/local/lib/node/.npm/connect/0.2.6/package/lib/connect/middleware/router.js:87:10) at next (/usr/local/lib/node/.npm/connect/0.2.6/package/lib/connect/index.js:264:23) at Object.bodyDecoder [as handle] (/usr/local/lib/node/.npm/connect/0.2.6/package/lib/connect/middleware/bodyDecoder.js:54:13) at next (/usr/local/lib/node/.npm/connect/0.2.6/package/lib/connect/index.js:264:23) at Object.handle (/usr/local/lib/node/.npm/express/1.0.0rc4/package/lib/express/server.js:61:9)


use connect's staticProvider http://senchalabs.github.com/connect/staticProvider.html :)

0

精彩评论

暂无评论...
验证码 换一张
取 消