I cloned a repo here https://github.com/willianjusten/bootstrap-boilerplate and do the following step.
git clone git://github.com/willianjusten/bootstrap-boilerplate.git new_project
cd bootstrap-boilerplate
npm install
gulp
The gulp does the work. But is the server started? In gulp js file I'm seeing the author use livereload, how do I start my development with that?
You can use nodemon (https://github.com/remy/nodemon). If any file is changed, nodemon will re-start automatically.
Sample usage
install
npm install -g nodemon
start node
nodemon server.js
Related
I inside the folder where the project is located through the command:
npm i gulp gulp-sass sass --save-dev
I have installed Gulp, but when I want to run it with this command in vs.code terminal :
gulp
I get an error, I wanted to know what caused the error?
On the system node js 14.1.0 & 16.13.0 and npm are already installed
The error message hints that gulp is not recognized as a command, I don't think this has anything to do with gulp-sass or sass specifically.
Option 1
Install gulp-cli globally:
npm i -g gulp-cli
glup-cli provides the executable gulp command, which will use the version of gulp is installed in your package. This is the preferred way to run gulp.
Option 2
Run gulp directly from your node_modules/.bin folder with the npx command. npx is set up by npm, so there is no need to install any additional packages.
npx gulp
or, equivalently
npm exec gulp
I have a NodeJS application which has only typescript files in it, no js files. I want to run in on my server in the background.
How can I archive that?
I tried using the npm package called forever but it only works with js files as it doesn't understand the typescript code.
You could use forever in combination with ts-node.
Here is a link to the npm package ts-node
I would suggest using the following command:
forever start -v -c ts-node app.ts
Where -v/--verbose is for turning on the verbose messages from Forever.
And -c is the COMMAND to execute which is default is node
This question is so old and forever now discourages to use it.
For new installations we encourage you to use pm2 or nodemon
Here is a quick tutorial on how to run your Typescript project as a background process.
Install PM2 globally:
npm install pm2 -g
Build your sources with Typescript default config:
tsc
You will have a new directory dist that contains your js files.
pm2 start dist/app.js
Bonus: you can monitor your app with the following command.
pm2 monit
first use
npm install -g ts-node
then use
forever start -v -c ts-node app.ts
it shuld start now
The two production quality recommendations I would make are:
Turn it into a docker container
Write a systemd service
Those are by far the best options. If for some reason this doesn't work:
pm2
supervisord
I'm going to run react-boilerplate application forever in the server.
I found forever and I'm not sure how I pass parameters to forever. The command to run server is like following:
PORT=80 npm run start:production
Seems like forever start PORT=80 npm run start:production doesn't help me.
One thing is that PORT=80 part is setting the env variable, this kind of command should be in front of other commands. The other thing is that to run npm scripts with forever, you need to use different syntax, so PORT=80 forever start -c "npm run start:production" /path/to/app/dir/.
If you're running forever form the project folder, the path should be ./
Or you can run a react application with pm2 or with nohup
1) install pm2 globally
npm install pm2 -g
2) navigate to the project folder and execute, space is required after --
pm2 start npm -- start
3) to see running instances
pm2 ps
4) to see the other options
pm2 --help
To run with nohup
1) navigate to the project folder
nohup bash -c 'npm start' &
pm2 is superb production process manager for Node. In addition to starting and daemonizing any application, it has a built in load balancer.
Install pm2:
npm install pm2 -g
To add start and add deamon to your app, navigate to the app folder and:
pm2 start app.js
To make pm2 autoboot on server restart:
$ pm2 startup
Then copy and paste the code generated.
For this you will need:
Install forever usingnpm install -g forever
Run the forever command PORT=<YOUR PORT> forever start -c "<command>" ./
Your command can be for example npm start and npm run dev.
Use ./ only if you are in the project folder.
Port means your port number, usually 80 or 443.
In my project directory, I installed Grunt by using the following command:
npm install grunt
...after that I did Grunt server in my project directory but it gives me command not found error.
Raj$ grunt server
-bash: grunt: command not found
And:
npm install grunt
npm WARN package.json BID-2.0#0.0.0 No description
npm WARN package.json BID-2.0#0.0.0 No repository field.
npm WARN package.json BID-2.0#0.0.0 No README data
How can I fix it?
You need to install Grunt's command line interface (CLI) globally as well.
From their site:
npm install -g grunt-cli
You may need to use sudo command (for OSX, *nix, BSD etc) or run your command shell as Administrator (for Windows) to do this.
This will put the grunt command in your system path, allowing it to be run from any directory.
You will have to install grunt after installing node / npm with: npm install -g grunt. Then it will be available at the cmd.
When I try to run the app.js file created by express, I get the following error:
$ node app.js
node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'express'
at Function._resolveFilename (module.js:320:11)
When I type in express --version I get a return statement of 2.3.3. I used npm to install express. I had to manually make npm using these instructions:
git clone http://github.com/isaacs/npm.git
cd npm
sudo make install
The error is Error: Cannot find module 'express'.
Do I need to do something after installing npm and express in order to make express see the modules created by npm?
My node is version: 0.4.6
My express is version: 2.3.3
My npm is version: 1.0.6
Express is installed globally. I used the -g flag to install it.
Edit: When I try "node -e require.paths" I get:
[ '/home/user/.node_modules',
'/home/user/.node_libraries',
'/usr/local/lib/node' ]
So, node isn't detecting the npm installation. How do I get node to detect the npm installation?
Install express
npm install -g express
Create a new app
express your_app
cd into app directory
cd your_app
use npm link to resolve modules
npm link express
Use local installs for require(), and global installs for command-line apps.
If you need both, use the npm link command.
On Ubuntu 12.04 you have to add the export NODE_PATH=/usr/local/lib/node_modules to your /.bashrc to use globally installed modules.
It appears that while npm had been updated to install global modules into /usr/local/lib/node_modules, Node's own require.paths does not yet reflect this change.
There are two reasonable solutions:
Add the following code to the top of your application:
require.paths.push('/usr/local/lib/node_modules');
Pro: non-invasive, easy to add
Con: requires discipline, future versions of node will restrict access to require.paths
As root, execute:
ln -s /usr/local/lib/node_modules /usr/local/lib/node
Pro: reasonably non-invasive
Con: requires root, modifies linux fs, might not survive system updates
I had the same problem. This worked for me though:
Seems like npm (now?) installs node modules to /usr/local/lib/node_modules/ and not /usr/local/lib/node/
What I did was simply to copy everything from node_modules to node: sudo cp -r /usr/local/lib/node_modules/* usr/local/lib/node/ and now it seems to be working for me.
Hope this helps you :-)
What about NODE_PATH=/usr/local/lib/node_modules in .bashrc or .bash_profile? I think it's the real correct way.
Set NODE_PATH=NODE_HOME\node_modules.
I'm using windows 7 and it works fine.
It may happen, if you're using windows, that the environment variable NODE_PATH is not set, and thus when you execute node fileName.js it won't find the libraries.
Check for the variable on your console, and if not present, create it. Give it the NODE_HOME\node_modules value, where NODE_HOME is your node install dir. This path is where npm install puts every module upon downloading.
require.paths is removed, use the NODE_PATH environment variable instead.
It looks like the easiest way to do this is to run npm install from your app's folder. This tells npm to hook everything up.
It's the last instruction after express <appname>:
...
dont forget to install dependencies:
$ cd <appname> && npm install
Finally with Linux a good way to do is to use the command : sudo apt-get install node-express
But with express 4 we must use express-generator to make app skeleton, install it with 'npm install express-generator -g', and then run 'express myapp' command.
see also install express
for mac users
cd /usr/local/lib/node
sudo ln -s ../node_modules/* ./$1
I installed gulp and when I ran this gulp command in the command line I got a gulp: command not found error. It appeared that it installed gulp in my local folder that is /home/YOURUSERNAME/.node/lib/node_modules and not in the global npm folder.
You can check npm root folder by running this command: npm root -g, which was returning my personal directory /home/YOURUSERNAME/.node/lib/node_modules and not the expected /usr/local/lib/node_modules.
You can fix this by running npm config set prefix /usr/local command.
For all problems with express with a mac computer:
The solution is:
chown to your user the .npm folder :
sudo chown -R Webmaste /Users/webmaste/.npm/
At your test folder or your folder:
sudo npm install -g express#2.5.8
Invoke express from your actual location:
/usr/local/share/npm/bin/express
sudo cd . && npm install
Finally:
node app
the final message in the console should look like this:
Express server listening on port 3000 in development mode