Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
how to clean imports Nodejs Mongodb socket io

I am Using MongoDB socket.io with nodeJs. Is there any way to clean up my imports

const express = require("express");
const app = express();
const { createServer } = require("http");
const httpServer = createServer(app);
const { Server } = require("socket.io");
const mongoose = require("mongoose");
var config = require("./config");
const url = config.mongoUrl;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Just use typescript, and then import with es6 syntax:

// tsconfig.json (at the root of your repository)
{
    "compilerOptions": {
      "target": "es5",
      "module": "commonjs",
      "lib": ["es6"],
      "allowJs": true,
      "outDir": "build",
      "rootDir": "src",
      "strict": false,
      "noImplicitAny": false,
      "skipLibCheck": true,
      "esModuleInterop": true,
      "resolveJsonModule": true,
      "baseUrl": "./",
    },
    "exclude": ["node_modules", "build"]
  }
  
// imports src/index.ts
import express from "express";
import { createServer } from "http";
import Mongoose from "mongoose";
import { Server } from "socket.io";
import { mongoUrl as url } from "./config"

export const app = express();
const server = createServer(app);
const io = new Server(server);

If you prefer to keep the require syntax, then you could shorten your app() declaration:

const app = require('express')();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!