Giter Club home page Giter Club logo

ifeanyi-production-api's Introduction

Here are some problems I faced, and how I solved them

ES6 Imports

Error

file:///C:/Users/IFEANYI/Documents/2024/production%20API/index.js:7
import corsOptions from "./config/corsOptions.js";
       ^^^^^^^^^^^
SyntaxError: The requested module './config/corsOptions.js' does not provide an export named 'default'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)

Solution

How to properly export a function and import the function in another file.

 // export a variable

 export const allowedOrigins = ["joy", "sam"];

 // import a variable

 import {allowedOrigins} from "./allowedOirgins.js"

How to import and export ES6

Redis server error

Error

Error Error: connect ECONNREFUSED ::1:6379

Solution

Remember to turn on the redis server.

open redis-cli.exe

redis-cli ping

If it returns "PONG", Redis is running. If it returns "Could not connect to Redis" or "Connection refused", then Redis is not running.

Redis server error

Dotenv

How to handle dotenv in your node.js code.

import dotenv from 'dotenv';
dotenv.config();

Explaining the dockerfile

FROM node:20-alpine // It instructs Docker to use a pre-built image containing Node.js version 20. This indicates that the base image is built on Alpine Linux, resulting in a smaller and more efficient Docker image.

LABEL maintainer="chimaifeanyi" // provide information about the image

WORKDIR /app // this will create a folder called app inside the image - 

COPY package*.json ./ // It copies the package.json file and potentially other matching files from your local project directory into the root directory (app) of the Docker image being built.

RUN npm install // this will install project dependencies in the container.

COPY . . // copy everything from our local project to work directory (app) in the docker image.

CMD ["node", "index.js"] // this is the command that will be used, when a container is created from the image

// when you start a container from this image, it will run the command (node index.js) to start the application.

EXPOSE 3500 // this tells docker that the nodejs application is running on port 3500 within the container

ifeanyi-production-api's People

Contributors

masterifeanyi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.