jaredhanson / passport-google-oauth2

Google authentication strategy for Passport and Node.js.
https://www.passportjs.org/packages/passport-google-oauth20/?utm_source=github&utm_medium=referral&utm_campaign=passport-google-oauth20&utm_content=about
MIT License
812 stars 154 forks source link

How to use it in using ES6 modules #89

Open pranavrai070 opened 1 year ago

pranavrai070 commented 1 year ago

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 commented 1 year ago

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 commented 11 months ago

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