I'm starting to develop with node.j,I meet an issue regarding the using of the module 'formidable'.
I have this error:
Error: Cannot find module 'formidable'
Here is the module list installed using 'npm ls installed' :
├─┬ express#2.5.9
│ ├── connect#1.8.7
│ ├── mime#1.2.4
│ ├── mkdirp#0.3.0
│ └── qs#0.4.2
├── formidable#1.0.9
├─┬ node-inspector#0.1.10
│ ├── paperboy#0.0.3
│ └─┬ socket.io#0.8.7
│ ├── policyfile#0.0.4
│ ├── redis#0.6.7
│ └─┬ socket.io-client#0.8.7
│ ├── uglify-js#1.0.6
│ ├── websocket-client#1.0.0
│ └── xmlhttprequest#1.2.2
├─┬ npm#1.1.21
│ ├── abbrev#1.0.3
│ ├── archy#0.0.2
│ ├── block-stream#0.0.5
│ ├── chownr#0.0.1
│ ├── fstream#0.1.18
│ ├─┬ fstream-npm#0.0.6
│ │ └── fstream-ignore#0.0.5
│ ├── graceful-fs#1.1.8
│ ├── inherits#1.0.0
│ ├── ini#1.0.2
│ ├── lru-cache#1.0.5
│ ├── minimatch#0.2.2
│ ├── mkdirp#0.3.0
│ ├─┬ node-gyp#0.4.1
│ │ ├── ansi#0.0.4
│ │ └── glob#3.1.9
│ ├── node-uuid#1.3.3
│ ├── nopt#1.0.10
│ ├── proto-list#1.0.0
│ ├── read#0.0.2
│ ├── request#2.9.153
│ ├── rimraf#2.0.1
│ ├── semver#1.0.13
│ ├── slide#1.1.3
│ ├── tar#0.1.13
│ ├── uid-number#0.0.3
│ └── which#1.0.5
└─┬ socket.io#0.9.6
├── policyfile#0.0.4
├── redis#0.6.7
└─┬ socket.io-client#0.9.6
├─┬ active-x-obfuscator#0.0.1
│ └── zeparser#0.0.5
├── uglify-js#1.2.5
├─┬ ws#0.4.14
│ ├── commander#0.5.2
│ └── options#0.0.3
└── xmlhttprequest#1.2.2
I add that it is the only module who generate this error.
Also, I don't really understand the way are encapsulated some module, it appears that npm is installing the module directly in the directory I'm using the module installation command, and I notice that formidable has been installed in the express/connect/ module on its first installation.
Can you give me more information about the module installation tree.
Thank for your replies
Cheers
The accepted answer looks very comprehensive and correct, but this worked for me:
npm install -d
d stands for dependencies (I think)
To understand module resolution, have a look at the Modules documentation, especially Loading from node_modules Folders.
For example, if the file at '/home/ry/projects/foo.js' called require('bar.js'), then node would look in the following locations, in this order:
/home/ry/projects/node_modules/bar.js
/home/ry/node_modules/bar.js
/home/node_modules/bar.js
/node_modules/bar.js
NPM takes advantage of this by installing modules into:
./node_modules/{module}
So, when you use npm install formidable, it will create and install the module into:
./node_modules/formidable
But, this means that only scripts within the current directory, including sub-directories, will succeed in using require('formidable'):
./foo.js
./lib/bar.js
./src/baz.js
./src/sub/qux.js
You can however install modules as "global," but you have to explicitly ask for it with -g or --global:
npm install -g formidable
Then, any script on the system should be able to require('formidable').
As for the tree output, you current have 5 installed modules available from the current directory:
express
formidable
node-inspector
npm
socket.io
Everything else in the tree is a list of these modules' dependencies, and their dependencies, etc., but only these 5 are available for require(...) within your scripts.
Related
I am working on an application using the MERN stack. The backend and frontend are in the same repository with this hierarchy:
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json
├── package.json
└── README.md
I want to have my constants shared between both the backend and frontend. I have the constants in the shared folder/module.
I also want to have any change in the shared package to be reflected in the other packages without needing to reinstall.
What is the best way for both the backend and frontend to use the shared package as a dependency?
You directory structure is almost ok to work with. But there might be some flaws,
my-project/
├── backend/
│ │
│ .
│ .
│ └── package.json
├── frontend/
│ │
│ .
│ .
│ └── package.json
├── shared/
│ ├── constants/
│ .
│ .
│ ├── index.js
│ └── package.json // You might not need this
├── package.json // define shared packages here
└── README.md
For more details, how node
I have created a debian virtual machine where I have installed meteor version 1.4.2.
I am working on the simple-todos meteor tutorial, blaze view.
I have done everything on step 2 [several times; even to the point of deleting and starting over many times]; I've even done straight c&p of all the code into the various files. I have spent several hours searching google; git-hub, and stackoverflow and have not found anything that seems to relate to my problem.
When I look at the app in the browser, the page is blank ... when I look in the console I have the following error code:
Uncaught Error: Cannot find module './template.body.js'
at require (http://localhost:3000/packages/modules-runtime.js?hash=ab7e8d32b6c7b5a5fa7ae1b65e8225c4f9e30223:119:19) [this error continues with a lot more references and hashes, but I can't post more than 2 links]
If someone could at least point me in the right direction so I can continue to research this, I would be most grateful.
OK, that's weird... I replicated what you were seeing. It happens when you have meteor RUNNING while doing this coding, so it is doing live code update, but the module is not being built/included properly.
All I did was STOP and restart Meteor. And it worked.
Not sure why it is not loading the modules in a rebuild and hot code push, but there you have it, that's the fix.
Here is my shell so you see what I did:
shaunst:~/workspace $ curl https://install.meteor.com/ | sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7784 0 7784 0 0 23942 0 --:--:-- --:--:-- --:--:-- 23950
Downloading Meteor distribution
######################################################################## 100.0%
Meteor 1.4.2 has been installed in your home directory (~/.meteor).
Writing a launcher script to /usr/local/bin/meteor for your convenience.
This may prompt for your password.
To get started fast:
$ meteor create ~/my_cool_app
$ cd ~/my_cool_app
$ meteor
Or see the docs at:
docs.meteor.com
shaunst:~/workspace $ meteor create simple-todos
Created a new Meteor app in 'simple-todos'.
To run your new app:
cd simple-todos
meteor
If you are new to Meteor, try some of the learning resources here:
https://www.meteor.com/learn
shaunst:~/workspace $ cd simple-todos/
shaunst:~/workspace/simple-todos $ meteor npm install
simple-todos# /home/ubuntu/workspace/simple-todos
└─┬ meteor-node-stubs#0.2.3
├── assert#1.3.0
├─┬ browserify-zlib#0.1.4
│ └── pako#0.2.8
├─┬ buffer#4.5.1
│ ├── base64-js#1.1.2
│ ├── ieee754#1.1.6
│ └── isarray#1.0.0
├─┬ console-browserify#1.1.0
│ └── date-now#0.1.4
├── constants-browserify#1.0.0
├─┬ crypto-browserify#3.11.0
│ ├─┬ browserify-cipher#1.0.0
│ │ ├─┬ browserify-aes#1.0.6
│ │ │ ├── buffer-xor#1.0.3
│ │ │ └── cipher-base#1.0.2
│ │ ├─┬ browserify-des#1.0.0
│ │ │ ├── cipher-base#1.0.2
│ │ │ └─┬ des.js#1.0.0
│ │ │ └── minimalistic-assert#1.0.0
│ │ └── evp_bytestokey#1.0.0
│ ├─┬ browserify-sign#4.0.0
│ │ ├── bn.js#4.11.1
│ │ ├── browserify-rsa#4.0.1
│ │ ├─┬ elliptic#6.2.3
│ │ │ ├── brorand#1.0.5
│ │ │ └── hash.js#1.0.3
│ │ └─┬ parse-asn1#5.0.0
│ │ ├─┬ asn1.js#4.5.2
│ │ │ └── minimalistic-assert#1.0.0
│ │ ├─┬ browserify-aes#1.0.6
│ │ │ ├── buffer-xor#1.0.3
│ │ │ └── cipher-base#1.0.2
│ │ └── evp_bytestokey#1.0.0
│ ├─┬ create-ecdh#4.0.0
│ │ ├── bn.js#4.11.1
│ │ └─┬ elliptic#6.2.3
│ │ ├── brorand#1.0.5
│ │ └── hash.js#1.0.3
│ ├─┬ create-hash#1.1.2
│ │ ├── cipher-base#1.0.2
│ │ ├── ripemd160#1.0.1
│ │ └── sha.js#2.4.5
│ ├── create-hmac#1.1.4
│ ├─┬ diffie-hellman#5.0.2
│ │ ├── bn.js#4.11.1
│ │ └─┬ miller-rabin#4.0.0
│ │ └── brorand#1.0.5
│ ├── inherits#2.0.1
│ ├── pbkdf2#3.0.4
│ ├─┬ public-encrypt#4.0.0
│ │ ├── bn.js#4.11.1
│ │ ├── browserify-rsa#4.0.1
│ │ └─┬ parse-asn1#5.0.0
│ │ ├─┬ asn1.js#4.5.2
│ │ │ └── minimalistic-assert#1.0.0
│ │ ├─┬ browserify-aes#1.0.6
│ │ │ ├── buffer-xor#1.0.3
│ │ │ └── cipher-base#1.0.2
│ │ └── evp_bytestokey#1.0.0
│ └── randombytes#2.0.3
├── domain-browser#1.1.7
├── events#1.1.0
├─┬ http-browserify#1.7.0
│ ├── Base64#0.2.1
│ └── inherits#2.0.1
├── https-browserify#0.0.1
├── os-browserify#0.2.1
├── path-browserify#0.0.0
├── process#0.11.2
├── punycode#1.4.1
├── querystring-es3#0.2.1
├─┬ readable-stream#2.0.6
│ ├── core-util-is#1.0.2
│ ├── inherits#2.0.1
│ ├── isarray#1.0.0
│ ├── process-nextick-args#1.0.6
│ └── util-deprecate#1.0.2
├─┬ stream-browserify#2.0.1
│ └── inherits#2.0.1
├── string_decoder#0.10.31
├── timers-browserify#1.4.2
├── tty-browserify#0.0.0
├─┬ url#0.11.0
│ ├── punycode#1.3.2
│ └── querystring#0.2.0
├─┬ util#0.10.3
│ └── inherits#2.0.1
└─┬ vm-browserify#0.0.4
└── indexof#0.0.1
shaunst:~/workspace/simple-todos $ meteor --port 8080
[[[[[ ~/workspace/simple-todos ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:8080/
=> Meteor server restarted
=> Meteor server restarted
=> Meteor server restarted
=> Meteor server restarted
=> Client modified -- refreshing (x3)
=> Meteor server restarted
=> Meteor server restarted
=> Client modified -- refreshing^C
shaunst:~/workspace/simple-todos $ ^C
shaunst:~/workspace/simple-todos $ meteor --port 8080
[[[[[ ~/workspace/simple-todos ]]]]]
=> Started proxy.
=> Started MongoDB.
=> Started your app.
=> App running at: http://localhost:8080/
=> Client modified -- refreshing (x2)
I'm experiencing the same.
I did as user Shaun Stoltz suggested (restart Meteor), and it did work. But then I added more files to the imports folder, and the error recurred, now referencing the new file missing 'template...'.
I gave Meteor another restart, and the build worked again.It seems that meteor omits the new files from the build while it's watching. Only upon restart the new files get included. This is a real nuisance as while following contemporary componental approach, i will be creating many small files, and restarting Meteor repeatedly is going to exhaust.
Are there other users experiencing this issue?
Set your project's Meteor version to a previous one:
meteor update --release 1.4.1.3
(Thanks to diaconutheodor)
Source
I am running meteor on a Mac using blaze templating. I have done the following steps and it has worked:
make sure that the import statement is in client/main.js and not in
server/main.js
make sure that 'blaze-html-templates' is installed
ensure that imports folder is typed correctly
Restart the server
If everything else fails, you can reset your project using 'meteor reset'
Hope this helps.
I am trying to compile my app on harp js. here is my directory structure.
.
├── 404.html
├── _harp
│ ├── 404.jade
│ ├── _data.json
│ ├── _harp.json
│ ├── _layout.jade
│ ├── index.jade
│ ├── main.less
│ └── public
│ ├── css
│ │ ├── bootstrap.css
│ │ ├── font-awesome.min.css
│ │ ├── hoverex-all.css
│ │ ├── prettyPhoto.css
│ │ └── style.css
│ └── js
│ ├── bootstrap.min.js
│ ├── custom.js
│ ├── jquery.hoverdir.js
│ ├── jquery.hoverex.min.js
│ ├── jquery.isotope.min.js
│ ├── jquery.prettyPhoto.js
│ ├── modernizr.min.js
│ └── retina-1.1.0.js
├── index.html
├── main.css
└── public
├── css
│ ├── bootstrap.css
│ ├── font-awesome.min.css
│ ├── hoverex-all.css
│ ├── prettyPhoto.css
│ └── style.css
└── js
now when i try to compile the app using
harp compile _harp ./
It is not compiling the js in the js directory. as you can see in the directory tree. the js directory is always blank. I have checked the permission it seems everything what I am missing?
I'm building an in-browser MVC application which will eventually run on a mobile device via PhoneGap. The app will communicate with the API server but will otherwise be completely independent. When I develop standard server-side MVC applications in Rails, the models, views, and controllers are separated into distinct files and directories. What's the standard practice with in-browser MVC apps? Are the MVC components usually defined within a single JS file, or are they usually separated out?
During the development phase, yes javascript files should be separated and well documented..
You can use requirejs to load your modules/views/collections separately.
Here is a great tutorial about Asynchronous Module Definitions (AMD). It's mainly about how you would organize your application using modules. I suggest you read it.
Below is the sample project structure the tutorial's author uses:
├── js
│ ├── libs
│ │ ├── jquery
│ │ │ ├── jquery.min.js
│ │ ├── backbone
│ │ │ ├── backbone.min.js
│ │ └── underscore
│ │ │ ├── underscore.min.js
│ ├── models
│ │ ├── users.js
│ │ └── projects.js
│ ├── collections
│ │ ├── users.js
│ │ └── projects.js
│ ├── views
│ │ ├── projects
│ │ │ ├── list.js
│ │ │ └── edit.js
│ │ └── users
│ │ ├── list.js
│ │ └── edit.js
│ ├── router.js
│ ├── app.js
│ ├── main.js
│ ├── order.js
│ └── text.js
└── index.html
For the validation/deployment phase, use a grunt-like tool to launch automated tasks. Such as concatenating and minifying javascript files into a single one. (It takes around 30 seconds depending on how you've configured it)
Here is an example of a grunt file.
I am trying to work out the best directory structure for a small Dojo application (it's a basic booking system).
I am just about finished writing login/registration.
Here is what I have now:
.
├── app
│ ├── client
│ │ ├── JsonRest.js
│ │ ├── lib
│ │ │ ├── defaultSubmit.js
│ │ │ ├── globals.js
│ │ │ ├── globalWidgets.js
│ │ │ ├── Logger.js
│ │ │ └── stores.js
│ │ ├── login.js
│ │ ├── main.css
│ │ ├── main.js
│ │ ├── register.js
│ │ ├── rrl.css
│ │ ├── TODO.txt
│ │ ├── validators.js
│ │ └── widgets
│ │ ├── _AjaxValidatorMixin.js
│ │ ├── AlertBar.js
│ │ ├── AppMainScreen.js
│ │ ├── BusyButton.js
│ │ ├── css
│ │ │ └── AlertBar.css
│ │ ├── Dashboard.js
│ │ ├── LoginForm.js
│ │ ├── RegisterForm.js
│ │ ├── SearchPage.js
│ │ ├── StackFading.js
│ │ ├── _StackFadingMixin.js
│ │ ├── TabFading.js
│ │ ├── templates
│ │ │ ├── LoginForm.html
│ │ │ ├── RetypePassword.html
│ │ │ └── SearchPage.html
│ │ ├── ValidationEmail.js
│ │ ├── ValidationPassword.js
│ │ ├── ValidationUsername.js
│ │ ├── ValidationWorkspace.js
│ └── server
│ ├── AppErrorHandler.js
│ ├── auth.js
│ ├── db.js
│ ├── globals.js
│ ├── node_modules
│ │ ├── express
│ │ ├── jade
│ │ ├── mongodb
│ │ └── mongoose
│ ├── public
│ │ ├── app -> ../../client/
│ │ └── libs -> ../../../libs
│ ├── routes
│ │ └── routes.js
│ ├── server.js
│ ├── test.js
│ └── views
│ ├── index.jade
│ ├── login.jade
│ └── register.jade
├── libs
├── build-report.txt
├── dojo -> dojo-1.7.1
├── dojo-1.7.1
│ ├── app -> ../../app/client
│ ├── dijit
│ ├── dojox
│ ├── dojo
│ └── util
└── dojo-1.8.0
├── app -> ../../app/client
├── dijit
├── dojox
├── dojo
└── util
The idea behind it is that:
the "app" directory will be in a git repository somewhere (it's about time I make one, actually). It has the directories "client" (all the client-side code) and "server" (the node code).
In "libs" I will add things like dgrid, etc. I also noticed that Dojo 1.8 can be loaded within node (!). I will play with this later -- exciting!
Now, here you can see that I basically used symbolic links to make things work.
SERVER side: Under "public", I had symlinks to "app" and "libs". That way, I can access, from HTML, things like /libs/dojo/dojox/form/resources/BusyButton.css, or (important!) /libs/dojo/dojo/dojo.js and /app/main.js (which then instances AppMainScreen with a simple require(["app/widgets/AppMainScreen" ], function( AppMainScreen){ ...
CLIENT side: I have a symlink to the latest Dojo (my boilerplate still has a problem with Dojo 1.8, so I am still using 1.7 for now). However, in order to make this work within the app:
require(["app/widgets/AppMainScreen" ], function( AppMainScreen){
I have a symlink to "app" within Dojo.
Now: I realise the basics (I think the symlink to "app" within Dojo is solved by simply using DojoConfig, for example). But... well, this is my current 100% unoptimised, never built tree.
I can ask you guys give me the tick of approval for this tree? Will it work once I start "building" things? (I am still miles away from doing it, but I will eventually otherwise my [pregnant] wife will go crazy!). Avoiding that symlink to "app" is one of the things I think I should do (but then again, do I need to?).
Thank you!
Merc.
While not being a fan (nor knowledgable at all) of node, it looks to me as there's a huuge javascript library :)
I'd suggest You should really consider making a buildprofile and use the prefix key to set the location of your scripts. As result of a build, you would automatically get an 'app' folder coexisting with dojo,dijit,dojox.
Actually, i would suggest that once there is a separate repository for your dojo application layer, simply do the checkout within the SDK root, e.g. :
wget download.dojotoolkit.org/dojotoolkit-1.7.2-src.tar.gz -O djsrc.tar.gz && tar xfz djsrc.tar.gz && rm djsrc.tar.gz
cd dojotoolkit-1.7.2-src/
svn checkout http://example/mylibrary app
sh utils/buildscripts/build.sh --profile app/package.profile --release /var/nodejs/docroot/lib/
There is no harm at all in developing your app.widgets somewhere else then in your main document root (/lib). You could simply setup one global variable that tells loader where to look.
If built, nothing should be nescessary, but as far as your current tree goes, try something like this
<script>
var isDevelopement = true;
var dojoConfig = {
packages : (isDevelopement) ? [ name: 'app', location: '/app/client/' ] : []
}
</script>