F
F
Finom2015-08-27 21:23:23
JavaScript
Finom, 2015-08-27 21:23:23

How to make friends node-babel and forever?

I am engaged in client development and decided that it would be time to master the node. I mainly write in ES7 (babel --stage=0), so I'm reluctant to switch to the "old" JS.
The problem is that I don't understand how I can use forever along with node-babel.
forever -w -c "babel-node" app.js
The script is executed remarkably, what is needed is written to the console. But after I change the script, I get an error:

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: listen EADDRINUSE
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1156:14)
    at listen (net.js:1182:10)
    at Server.listen (net.js:1267:5)
    at EventEmitter.listen (/home/finom/Dropbox/Public/sync/ag/my/tests/matreshka_website_node/node_modules/express/lib/application.js:617:24)
    at Object.<anonymous> (/home/finom/Dropbox/Public/sync/ag/my/tests/matreshka_website_node/app.js:28:5)
    at Module._compile (module.js:460:26)
    at normalLoader (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:199:5)
    at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/babel/node_modules/babel-core/lib/api/register/node.js:216:7)
    at Module.load (module.js:355:32)
error: Forever detected script exited with code: 1

CHADNT?
Google says that this error occurs when a node tries to use a port that is already in use. But I don't understand how to solve this problem.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Finom, 2015-09-01
@Finom

He asked, he answered. Instead of using babel-node, you need to use a regular node, which in the application's initialization file calls.
require('babel/register');

N
Nikita Gushchin, 2015-08-27
@iNikNik

Do you know what forever is for?
This means that you run your app.js script that listens on some port (occupied it), then (apparently) you try to run another script that tries to connect to the same port and get an error - address (port) already taken.
Kill the previous script, and then start the new one.

B
BondDen, 2015-08-30
@BondDen

If I understand your problem correctly, I recommend getting acquainted with gulp .
gulpfile.js in your case might look like this:

var gulp   =require('gulp'),
    util   =require('gulp-util'),
    changed=require('gulp-changed'),
    rename =require('gulp-rename'),
    babel  =require('gulp-babel'),
    plumber=require('gulp-plumber'),
    path   =require('path')
;
var d      ={
  js  :{
    src  :'src/*.es7.js',
    dst  :'./'
  }
};

gulp.task('js',function(){
  return gulp.src(d.js.src)
    .pipe(plumber())
    .pipe(changed(d.js.dst))
    .pipe(babel({stage:0}))
    .pipe(rename(function(path){
      path.basename=path.basename.replace('.es7','');
    }))
    .pipe(gulp.dest(d.js.dst));
});

gulp.task('watch',function(){
  gulp.watch(d.js.src,['js']);
});

gulp.task('default',['watch','js']);

the plumber module is used here, just to ensure the continuous operation of the compiler.
and the gulp.watch method monitors file changes in real time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question