I am using the modular folder structure shown here by tjholowaychuk.
Is it somehow possible to also have a separate client JS in each of these modules? Currently all my client JS is in the /assets/js folder, but it would be nice to have a JS file in the module instead.
After playing around with it, the best solution for me seems to be to put the client js under lib/module/client/, and then just use this path in the script tag. This way I can have a client js file for each module.
Related
I am developing a rails app. It has javascript functionality in app/assets/javascript. Now I have multiple javascript files. I want to use method from one javascript file in another file.
I tried export, import concept.
My doubt is what should be the path in import? cause I am running this app in local environment.
if my path is this
"/home/manoharsinhrana/workspace/copy/housing.ads.service/app/assets/javascripts/ad_products/utility.js it "
It would not work in production.
I am working on a project using AngularJS and NodeJS. I am new to both frameworks and need some help for reading in (text) files.
I am trying to read files using npm's read-file (https://www.npmjs.com/package/read-file).
I put var read = require('read-file') into one of my controllers Javascript files, but I keep getting an error message Cannot find module 'read-file'
Below is the current project structure:
my_project
|--app
|--bower_components
|--components
|--scripts
|--controllers
|--my_controller.js
|--styles
|--views
|--my_page.html
|--app.js
|--index.html
|--node_modules
|--read-file
|--index.js
|--LICENSE
|--package.json
|--README.md
Clearly I installed the read-file module, but I think there is an issue locating it. What should I do to make sure that require('read-file') correctly locates the read-file module?
Any help will be appreciated. Thanks!
It seems that you are trying to read the read-file module within your Angular.js application controller. The controllers within Angular.js are front end files and are run from within the Browser environment and not Node.js. Therefore, you cannot use utilities such as require within the browser.
I think you may be able to achieve what you are trying to accomplish by running your front end application through a tool like Browserify. This will allow you to use Node.js to do stuff like require which will load the file during compilation time and allow you to require files within the browser. You can also use Node.js tools such as fs to load the contents of files and include them within your front end application. I think this should get you pretty close.
I think you are trying to load the read-file module in the client js part, where is not defined at all.
You should create your node server here, and create an api you should call from your front-end controller that load get the file.
From the node api handler you read the file and send back to the client when requested.
I'm using browserify to pack my app and use js files as modules.
Now I want to use a webworker to upload a very big file on the background.
The problem I have is that to create this worker the instruction
new Worker('./worker.js')
must receive the name of a js file. So that this file cannot be a module. I think that this makes my app much more complicated, because now I have to combine two ways of using js files.
On the other hand, I'm interested in accessing a browserify module from this worker too.
So the question is, Which is the best way of using browserify and web workers together?
You can use webworkify to handle this
Maybe it's a stupid question but i am a newbie using node js, and I think that it can be used just with js files, I dont know, I installed node js on my windows and i started the web server but i dont know how to run the files, I have always worked with apache, I saw there is a folder called scrips in the node js installation folder
but i dont know how to run the files, I have always worked with apache.
In NodeJS, it's either you write the web server (it's like writing Apache itself), or use a framework that does it for you (it's like adding in something like Apache). Suggesting you check out Express. It's something almost close to CodeIgniter (writing points of entry).
Can i run a php file or a html file in a node js web server?
NodeJS is for JS. Your server files are all in JS. As for HTML, checkout Express (mentioned above), or if you just want to serve plain HTML (or static files), you may want to check out Connect Static
I am using meteor, which I am new to, for my current project and want to replace the current chessboard I made with that from chessboardjs.com and was hoping some one may have experience with this. I downloaded the files from the website, put the css files in a css directory I created and the images in my public/image directory but was wondering where to place the .js files. I am not used to working with multiple files in meteor. I am creating a client and server directory. Should I just place the .js files in the client directory? Also, on the site it says to get started add
to the javascript
var board1 = new ChessBoard('board1', 'start');
and to the html
Could some one suggest a way to use meteor templates to put this in the .js files? I am a bit confused.
You should place external client libraries somewhere in /client folder. Usually it's either /client/lib to ensure they're loaded before the rest of your code, or /client/compatibility to ensure they work even if they aren't designed to work with Meteor, or /client/lib/compatibility for both.