Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

280
Visualizações
How can I signal NodeJS (Gulp Specifically) with a callback when Express server starts?

I'm trying to create a gulp workflow that includes nodemon, typescript, and browsersync. When I try to reload the browser with browsersync the browser reloads before the express server has had a chance to finish creating routes, etc. So in the end I have to reload the browser manually anyway (f5). I have tried to use gulp-nodemon events, gulp.watch(), and gulp-nodemon tasks in the config. All to no avail. I'm thinking that if it's possible, I can notify nodemon that Express is ready and manually trigger the page load or maybe even notify browsersync in the browser from express to reload the page.

for simplicity here is a small version of my gulpfile:

const browser = require('browser-sync');

gulp.task('typescript', function(){
  return gulp.src(config.src + '/**/*.ts')
    .pipe(tsProject())
    .pipe(gulp.dest(config.dist));
});

gulp.task('server', function (done) {

    // Create nodemon instance
    $.nodemon({
        script: config.dist + '/app.js',
        watch: config.src + '/**/*',
        ext: '*.*',
        env: {
            'NODE_ENV': 'development'
        },
        tasks: ['typescript'] 
    }).on('start',function(done){
        browser.reload();
    });
    done();
});

gulp.task('sync', function (done) {
     // Init browser-sync
    browser.init({
        port: 3000,
        proxy: 'localhost:8000'
    });
    done();
};

gulp.task('default', gulp.series(clean, 'typescript', 'server', 'sync'));

For the most part everything works. TypeScript transpiles, Nodemon starts serving the Express app, and BrowserSync launches successfully. On changes the Typescript transpiles, Nodemon restarts the Express app, and BrowserSync reloads. The problem is BrowserSync reloads before Express has a chance to start listening for connections. Any suggestions?

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda