how to load socket.io without npm in node.exe? - node.js

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!

Related

Unable to access socket.io module from node console

Please check this image here, as I can't display it here directly. I have installed socket.io module globally and even i have tried it installing locally inside PushNotification directory. I am still getting the error "Error: Cannot find module 'socket.io'".
don't use socket.io in global npm (-g)
install it locally in your project
npm -install socket.io --save
Node has no idea where to find socket.io when you install it globally. Global module installs are really only for command line level tools, that have to be linked to your PATH, so that you can call them from outside the node env. The most obvious of which is npm e.g. npm install.
When you installed socket.io globally, you ended up putting it in /usr/local/lib, which is not in the list of locations that node looks for module requires. Node looks in a few locations when it encounters a require statement:
Node core module
if path, look in project path
else look in node_modules path
None of these locations match /usr/local/lib, so node throws a "not found" error.
Read more about require here.
To answer your other question, if you install socket.io in your node_modules folder, and then in the node command line require('socket.io'), it will end up looking in your node_modules folder and finding socket.io, so you can easily use it from inside the node command line.

npm package install issues

I'm having a problem with npm.
When I install packages they will go to the node_modules folder, but instead of the package assets being in one folder it puts them outside of that folder.
In the express folder, all of the folders in that are supposed to be inside, but instead, they are outside of it. This also happens with other packages I try to install. I have tried creating a test project, but the same thing happened,
And I also tried uninstalling node and npm, and it is still happening.
You sure it's not dependencies?
NPM will install additional packages if you need them, and place them in root of the node_modules folder so that other modules later can use the same if they need them.
After running (edit: npm init first to get package.json in the root of the project) npm install express --save on empty project, I end up with
PS. Apologies if I misused terms, I'm still quiet new to node and npm
I found out what happened it was because of node v5.1.1 that the package folders were saving outside of the express folder once I went back to node v4.2.3 it made a node_modules folder inside the express folder.
Thanks again for everyones help

how do I access my module in express?

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

emberjs, node and dependencies

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';

Managing client side scripts with npm

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

Resources