我在NodeJS项目中安装了DateJS,以便于处理添加月份.我在package.json中添加了它. "datejs": "*" 然后安装它: root@v-hj-0190:~/deepak/appJade# npm -d installnpm info it worked if it ends with oknpm info using npm@1.4.
"datejs": "*"
然后安装它:
root@v-hj-0190:~/deepak/appJade# npm -d install npm info it worked if it ends with ok npm info using npm@1.4.28 npm info using node@v0.10.33 npm info preinstall appJade@0.0.0 npm info trying registry request attempt 1 at 15:08:34 npm http GET https://registry.npmjs.org/datejs npm http 304 https://registry.npmjs.org/datejs npm info install datejs@1.0.0-rc3 into /root/deepak/appJade npm info installOne datejs@1.0.0-rc3 npm info preinstall datejs@1.0.0-rc3 npm info build /root/deepak/appJade/node_modules/datejs npm info linkStuff datejs@1.0.0-rc3 npm info install datejs@1.0.0-rc3 npm info postinstall datejs@1.0.0-rc3 npm info build /root/deepak/appJade npm info linkStuff appJade@0.0.0 npm info install appJade@0.0.0 npm info postinstall appJade@0.0.0 npm info prepublish appJade@0.0.0 datejs@1.0.0-rc3 node_modules/datejs npm info ok root@v-hj-0190:~/deepak/appJade#
我在app.js中添加了require行
... var bodyParser = require('body-parser'); var Date = require('datejs'); ...
但以下代码仍然给出错误:
var approvalDate = Date.today(); ^ TypeError: Object function Date() { [native code] } has no method 'today' .. var n = 6; console.log(n.months().fromNow()); ^ TypeError: Object 6 has no method 'months'
注意:我是NodeJS的新手,需要有关如何在项目中集成/使用DateJS的示例.只提供了直接的功能.
datejs通过扩展日期内置的javascript来工作,因此无需将require分配给变量.代替..var Date = require('datejs');
只是做要求:
require('datejs')
然后当你全部设置时(或者,如果你有理由将模块分配给变量,请使用“Date”之外的其他内容).