Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use it in using ES6 modules #89

Open
pranavrai070 opened this issue Dec 17, 2022 · 2 comments
Open

How to use it in using ES6 modules #89

pranavrai070 opened this issue Dec 17, 2022 · 2 comments

Comments

@pranavrai070
Copy link

import dotenv from "dotenv";
dotenv.config({ silent: process.env.NODE_ENV === 'production' });
const session = require('express-session');
const passport = require("passport");
import express from 'express';
import bodyParser from 'body-parser';
import mongoose from 'mongoose';
import cors from 'cors'; //doubt
import postRoutes from './routes/posts.js';
import userRouter from "./routes/user.js";

How to make the above code work in using 3rd party libraries like one without ES6 .

@patankaranup
Copy link

patankaranup commented Jan 28, 2023

To make the above code work in a environment that doesn't support ES6 imports, you would need to use the CommonJS require syntax instead of the ES6 import syntax. Here's how the code would look:

const dotenv = require("dotenv");
dotenv.config({ silent: process.env.NODE_ENV === 'production' });
const session = require('express-session');
const passport = require("passport");
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const cors = require('cors'); 
const postRoutes = require('./routes/posts.js');
const userRouter = require("./routes/user.js");

@malik991
Copy link

if you use CommonJS then please update package.json also. ( remove "type": "module")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants