now.js - Hello World example - “require not defined”

冷暖自知 提交于 2019-12-05 20:56:52

The file you're including in your client source (../Flotype/now/master/lib/now.js) is the Node server side code that is included in your node process when calling now = require 'now'.

So changing your included client source file from .../Flotype/now/master/lib/now.js to /nowjs/now.js will fix your problem.

Where does this /nowjs/now.js file come from?

When using NowJS (and many other npm packages that do client/server communication) you extend the server object. This is done with the line everyone = now.initialize(server) (Code Here).

What the initialize function does is wrap your server with the fileServer (Code Here) class in NowJS. This adds a resource under the "folder" nowjs which serves the client now.js file.

I got this error when trying to run nodejs file with js command instead of node. Eg: if the nodejs file name is test.js, I was doing

js test.js

instead of node test.js

I hope this helps too for people searching for this error.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!