Can't build my web application when integrating bootstrap template - node.js

I'm totally new to Node.js meteor and all development outside of visual studio.
When I go in the console and add bootstrap like this :
npm install twitter-bootstrap
It gets installed and adds all the bootstrap files in my solution but when I run my application with meteor it says
Process finished with exit code 254
No more information. No errors. If I delete all the bootstrap files, it builds and run just fine. Any idea what might be causing this?
I've tried looking for the exit code meaning but I can't find it for my IDE and I'm a bit clueless as for why simply adding those packages without even referencing them anywhere in the project might cause my application not to run at all.

You can't add npm packages in your project folder like that. It will create a node_modules sub-directory that meteor will treat like any other project folder, i.e., it will interpret all the files in it. That's not what you want. Either do the npm install in a super-directory, or, better yet, use the meteor meteorhacks:npm package (https://atmospherejs.com/meteorhacks/npm):
meteor add meteorhacks:npm
and then add the npm dependency to your packages.json file.
{
"twitter-bootstrap": "2.1.1"
}
But the real question is: why do you need this package? bootstrap3 is already part of the standard meteor packages, i.e., you already have full access to bootstrap, incl. javascript.

You can use atmosphere meteor packages called mizzao:bootstrap-3 by running the commend
meteor add mizzoa:bootstrap-3
Alternatively if you want to use npm packages you must add meteorhacks:npm packages.
meteor add meteorhacks:npm
npm install twitter-bootstrap
You can specify all the required npm packages inside a packages.json file.
{
"gm":"1.16.0",
"twitter":"0.2.12",
"twitter-bootstrap":"2.1.1",
}

Related

NPM not installing node module

I have an angular project that comes with a package.json file and all the dependencies listed within, but each time I run "npm install", in the terminal, the packages appear to be downloading properly and a node module folder is created in my root folder, but at a certain stage the installation stops without an error message and the generated node module folder disappear from my project. please what do I do?
I can't reproduce your situation, somehow this may not fitable for you.
But I suggest re-install node.js to make sure npm install work correctly.
This link will help to find what version of node.js for you, based on you angular version.
Compatibility list for Angular/Angular-CLI and Node.js
Also, It would be good to manage node.js via NVM(Node Version Manager).

Changing npm module in the node-modules folder

I want to do some changes to an npm-module I already installed in node-modules folder ... I mean edit the code of the locally installed module
My question is ... should I re-run my react-native app with every change I made to see that change in action?
If yes...
I there a better and faster way for testing my changes?
If you change a Module Version in node-modules you have to rerun npm install and then start your app up again.
The app has to be rebuild/restarted beacuse it useses a newer Version of a module.
Normal Code changes not depending the node-modules can be refreshed without rebuilding the app with react natives hot reload.
This is not really an answer but more of a suggestion.
It's better that you don't change it inside the node modules directory if you want to reuse it somewhere else. You will also have trouble dealing with updates.
One way to handle it better maybe to fork the repo of the npm package in GitHub and then modify whatever you have to in that repo. Finally instead of installing that package, install your copy by specifying dependency in package.json like
"module-name": "https://github.com/<your userame>/<module repo>
or you could directly install using:
npm install https://github.com/<your userame>/<module repo>
The URL can be either the https or ssh URL of the repo.
More details on installing packages from Github repo
Also, regarding your question, if you use the above method, you will have to re-run your app after updating the package.

What are the components of an Angular/Node/ng application? What does each do and how are they related?

I'm having version issues installing npm/node/angular/ng. What are the different components of an Angular/Node/ng application and how are they related? Are there bundled packages that include everything you need to start developing in a single download? The current project I'm on is managing all of this through npm and is going through the common growing pains of changing versions and changing components and changing dependencies. The npm documentation is good for npm basics but is there documentation that describes best (or common, or recommended) practices for installing everything needed for Angular/node/ng applications (#angular-devkit, #angular-cdk, #schematics/angular, ng, etc.).
The starting point is as follows visiting https://cli.angular.io/ which shows you how to start an Angular app from scratch using Angular CLI.
Now let's say you create a temp folder and do the following as described in above link:
npm install -g #angular/cli
ng new my-dream-app
cd my-dream-app
ng serve
Go to this folder and check the package.json file in the root of that project against yours. That should surely give you the idea of which packages you have.
As the next step run the following command
npm-check -u
and as the final tip: every now and then delete the contents of node_modules (make sure you have everything backed up) and do a
npm install
Then run
ng build --prod
This way around you can always be sure if you clone your app on some other machine, you can install all the dependencies and resume work and also your project builds with no issue.

I don't know why the core modules in node js are not being recognized within my project using IntelliJ Idea (2016)

I keep getting the error: Cannot find module 'serve-favicon.' This error occurs not just for serve-favicon but for all core modules which also includes 'body-parser', 'cookie-parser', etc. I am using IntelliJ IDEA (version: 2016). I already enabled the Node.js Core library, and I have been able to use core modules in other projects successfully. What is different about this project however, is that I pulled it from github. Do I need to install another plugin? If yes, which one? Do I need to add another package?
serve-favicon, body-parser, cookie-parser are not node.js core modules.
You will need to install these dependencies from npm registry. To install these dependencies, you will need to run
npm install <package-name> --save
If you have pulled the project from github, chances are there will be a package.json file with a list of dependencies. In that case, all you need to do is run npm install from the project folder.

cannot find module express, how to install it to make it globally available?

I want to experiment with some node.js stuff and I installed it yesterday following someone's instructions on the web which got it up and running, and I got the standard Hello World web page up on the screen.
I now went to move onto another example, but in order to not clutter my home directory, I created a directory off of it (~/node) and created the files I needed in there. Low and behold, when it came time to run the service, I got no joy stating the express module couldn't be found.
The instructions told me to install express using the -g flag, but that didn't help. I even ran it again without any luck.
Now I've found this:
Cannot find module `express` | socket.io [node.js]
and it appears I have to install it again under the current directory. I have done that and it works. Is it the case it has to be installed under each directory that I want services running from? It seems an unnecessary duplication.
edit:
Not knowing much about js I thought I would go digging and found
app.use(express['static'](__dirname ));
and have realised this is probably the cause of my problem. Further research has found this: http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders and if I install it once in a higher level directory, that should 'solve' my problem. I'm not going to bother about uninstalling the module, but for my next project I will try it and see how it goes.
I don't know why the original author suggested the -g flag when installing express, since it hasn't seemed to work for me.
NPM is a really nice tool, allowing you to install node.js modules locally and globally.
Local module installation
If you want to use a module for your project, you have to install it locally.
That's why npm creates a subdirectory called node_modules inside your project directory.
If you use the same module for two different projects, npm will download the module and install it twice. That's perfectly normal, it helps you manage different versions of the same dependency.
The best way to manage dependencies and install modules for a specific project is to fill the package.json with your dependencies and install them using
npm install
inside your project directory.
To access your modules in your code, use the require() function.
For example, with expressjs :
var express = require('express');
var app = express();
...
Global module installation
npm allows you to install modules globally as well. But remember that installing a module globally only provides more commands in your terminal, as with expressjs and express(1).
In order to install expressjs globally, run this in your terminal
npm install -g express
If you want to use a globally installed module in a specific project, you also have to install it locally (in your project directory, without -g).
I hope this answers clearly your question.
Express is capable of generating a simple app structure when installed globally. See this link and scroll to Using express(1) to generate an app section. It's a good way to get you started easily.
Take a look into package.json, package.json in nodejitsu
All npm packages contain a file, usually in the project root, called package.json - this file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies
a package.json example:
{
"name": "CRUD",
"description": "A simple CRUD",
"author": "Only for learn",
"dependencies": {
"express": "*",
},
}
so for install the dependencies go to level that package.json is, and run npm install this one will install all the dependencies you need for the project.
EDIT
a package.json interactive guide
I have found that when setting up node.js projects and dependencies, using Grunt [http://gruntjs.com/] has a lot of advantages. Although there are lots of different ways to setup a node and express project there is a lot to be said for using the Douglas Crockford approach and 'going with the grain'. In this case Grunt is the grain as it is becoming the de-facto standard for setting up a node project and there are existing templates for the most common types of node.js projects. You can find Grunt Express here [https://github.com/blai/grunt-express].
In this case Grunt would provide you with a project structure consistent with others, setup dependencies file for the node package manager and auto generate the express project for you. Packages are kept in a node_modules directory. If you are familiar with maven you might recognize the 'convention over configuration approach'.

Resources