I install bootstrap with
npm install bootstrap --save
in my express project, then bootstrap is installed in node_modules, but how can I access the js and css in my jade file?
Node_modules is meant to use for server modules. NPM is server package management system.
You should use client package management system like bower for your client side modules i.e. Bootstrap.
Once you set up bower, you'll be able to reference bower_components in your html files.
It depends on how you configure your static server, e.g.:
app.use(express.static('public'));
So if node_modules is placed into public folder, your jade file will be:
script(src='/node_modules/bootstrap/js/file.js')
But better approach is use bower_component instead of node_modules on the client-side
Related
I just got started with Node.js and found that we need to RequireJS library on the backend. Also, we need to include it in view if we want to use it there. So, if I want to use d3 to manipulate some data I will specify require in backend and send the result only to front end? Or should I include it in both server side and HTML page? So is it redundant that using same library on both sides?
For jQuery: I did
npm install jquery
For Bootstrap:
npm install bootstrap
Now as the version does not match, I am including different jQuery in HTML file. Again I added d3 from scripts. Although it works, is this the proper way to design a Node.js app?
You do not want to use npm for the client side part of the application (bootstrap included). I would recommend installing bower.
npm install bower
bower init
Create a .bowerrc file and put in it { "directory" : "public/components"}
bower install bootstrap --save
Include the script in the html file.
I declare dependencies in my app.js (ember) file, such as:
var _ = require('underscore');
Since my app.js file will be sent to the client and need to execute in a browser, how would this code be made available to the client?
Currently I'm using lineman to concatenate and uglify all my js files, and inside my vendors folder I did include underscore.min.js (all of this get bundled up into app.js) - yet my app isn't working.
Could someone kindly explain the process of adding npm packages to an ember app and the resulting requirements on the client side?
You can use Ember Browserify to use node packages in your ember app.
See this answer for specific usage.
To install Ember Browserify:
npm install --save-dev ember-browserify
and utilize something from a package isntalled through NPM:
import Xyz from 'npm:xyzPackage';
I don't really know where the bower_components directory came from in my Node Express app but it seems to be competing for attention with my node_modules folder since both contain jquery and bootstrap.
I am using Browserify and am trying to bundle up jquery, bootstrap and some other components. What exactly is going on here with Bower? Do I need Bower for anything?
For instance, when I do a require('jquery') in my application code how do I know if it's coming from the NPM node_modules or Bower bower_components?
Basic browserify can only use node_modules.
To use with bower, it can use transform before import node_modules.
If you use debowerify transform, it will import bower_components before node_modules. So if your bower.json has jquery and bootstrap, it will use bower_components'.
If you use browserify-shim transform, it will search your package.json's browser field. So if your browser field has jquery and bootstrap, it will use it.
Is it possible with NPM to manage the same dependencies for backend and the client-side scripts? I'm building a node.js application with express. When installing all dependencies, those scripts are installed into the node_modules folder. Is it possible to somehow tell express that it should look in those folder for javascript files for the client? E.g. when the client requests the file underscore.js, it should return the file from the installed module. Or is it possible to hook in to the npm installation procedure so that some files can be automatically copied to the public folder of the application?
You can hook into NPM after it installs the packages required by your application using postinstall in the scripts field in package.json:
install, postinstall: Run AFTER the package is installed.
For more read here: http://npmjs.org/doc/scripts.html
How can I include a package like socket.io in node.exe(windows)?
I tried this but it doesn't work:
var socketio = require("./socketio/socket.io")
While my package.json file is stored in a folder called socketio where is in same folder as node.exe is located.
I bundled socket.io via npm inside node_modules. You can download the zip(extract it first) and just use it thanks to node_modules.
You don't want to use NPM, but you do have a package.json(strange)? My advice would be to just install it via NPM. That's what package managers are for!