Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
How can I create a build from a JavaScript file based on node modules?

I created a new node project using

npm init
npm install apollo-server

I then added a index.js file with the following code:

const { ApolloServer, gql } = require('apollo-server');

const typeDefs = gql`
  type Query {
    hello: String
  }
`;

const server = new ApolloServer({
  typeDefs,
  mocks: true,
});

server.listen().then(({ url }) => {
  console.log(`🚀 Server ready at ${url}`)
});

While I can run this with node index.js, how could I actually create a build from my index.js so it doesn't directly need the modules during runtime? (goal: deploy it on platforms like e.g. render.com)

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It sounds like you want to create a single executable artifact which requires no server-side configuration or setup to run.

There are a few options for this. You're probably looking for a Javascript bundler, like Rollup, Parcel or Webpack. Webpack is the most widely used, but also generally the most difficult to configure.

Using bundlers

Parcel

Install Parcel with npm i -g parcel, then, add this to your package.json:

  "main": "dist/index.js",
  "targets": {
    "main": {
      "includeNodeModules": true
    },
  },

Then run parcel build index.js. That's it!

I've added a simple demo on GitHub.

Webpack

There are a number of great answers on this SO question.

Bundler caveats

Many node packages come with binary/native addons. For example, Cypress downloads and installs a browser. Any package which uses native addons will not work with a bundler, as the bundler is unable to add the binary files. These packages will still need to be installed.

Another option: building a binary

In the processes above, your output artifact is a single Javascript file. Instead of a Javascript file, you could also produce a binary file and thus alleviate the need to install the Node runtime. Check out pkg to do this. While pkg is a fairly mature product, this is generally still considered an experimental technology, so perhaps not suited for a production environment. On the other hand, you shouldn't run into any problems with packages that include native addons. Read the documentation to see if it's appropriate for your use case.

about 4 years ago · Juan Pablo Isaza Denunciar

0

https://github.com/vercel/ncc this might help. it includes node_modules in the final artifact

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda