chilin70
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Fix up L5 environment ## info * TOC [toc] * [repo link](https://github.com/bradtraversy/mern_shopping_list) * 建議 client 與 server 分開跑容易除錯,不要直接 ```npm start``` 或是 ```npm run dev``` * 底下 ```$``` 開頭為 shell command,若為 windows cmd 請使用相對應指令 (or using ```WSL```) * p.s. 我是在自己電腦上安裝 MongoDB ## client side ### error of babel-loader * 路徑: ``` mern_shopping_list/package.json ``` * 原先內容: ```js=27 "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.3", "babel-loader": "^8.0.6", "babel-preset-env": "^1.7.0", "morgan": "^1.9.1", ``` * 修改: * 若已經下載 module 了請先刪除: ```sh $ rm -rf node_modules $ rm package-lock.json ``` * 直接刪除原先 ```package.json``` 中第 30 行: ```js=27 "devDependencies": { "babel-cli": "^6.26.0", "babel-core": "^6.26.3", "babel-preset-env": "^1.7.0", "morgan": "^1.9.1", ``` * 重新下載: ```sh $ npm install $ npm run client-install ``` * test: ```sh $ npm run client ``` ### error of pretty-format * 無法成功 compile 並顯示以下頁面或是顯示錯誤訊息於 terminal 中: ![](https://i.imgur.com/X7gxIw8.png) * 修正 ```pretty-format``` module 原始碼: * 路徑: ``` mern_shopping_list/client/node_modules/pretty-format/build/index.d.ts ``` * source code 應該會長下面這樣: ```js=1 /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import type { NewPlugin, Options, OptionsReceived } from './types'; export type { Colors, CompareKeys, Config, Options, OptionsReceived, OldPlugin, NewPlugin, Plugin, Plugins, PrettyFormatOptions, Printer, Refs, Theme, } from './types'; export declare const DEFAULT_OPTIONS: Options; /** ``` * 修改原先第 7, 8 行: ```js=1 /** * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import * as PrettyFormat from './types'; export declare const DEFAULT_OPTIONS: Options; /** * Returns a presentation string of your `val` object ``` * test: ```sh $ npm run client ``` ## server ### error of connection * 在啟動前先做好 DB 設定: * ```config/default.json``` ```js { "mongoURI": "mongodb://localhost:27017", "jwtSecret": "sl_myJwtSecret" } ``` * 若出現下面錯誤訊息表示後端與資料庫連接有問題,很可能是兩個原因: ``` MongoParseError: Invalid connection string at parseConnectionString (/home/chilin/mern_shopping_list/node_modules/mongodb/lib/core/uri_parser.js:585:21) at connect (/home/chilin/mern_shopping_list/node_modules/mongodb/lib/operations/connect.js:283:3) at /home/chilin/mern_shopping_list/node_modules/mongodb/lib/mongo_client.js:284:5 at maybePromise (/home/chilin/mern_shopping_list/node_modules/mongodb/lib/utils.js:692:3) at MongoClient.connect (/home/chilin/mern_shopping_list/node_modules/mongodb/lib/mongo_client.js:280:10) at /home/chilin/mern_shopping_list/node_modules/mongoose/lib/connection.js:836:12 at new Promise (<anonymous>) at NativeConnection.Connection.openUri (/home/chilin/mern_shopping_list/node_modules/mongoose/lib/connection.js:832:19) at /home/chilin/mern_shopping_list/node_modules/mongoose/lib/index.js:351:10 at /home/chilin/mern_shopping_list/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5 at new Promise (<anonymous>) at promiseOrCallback (/home/chilin/mern_shopping_list/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10) at Mongoose._promiseOrCallback (/home/chilin/mern_shopping_list/node_modules/mongoose/lib/index.js:1149:10) at Mongoose.connect (/home/chilin/mern_shopping_list/node_modules/mongoose/lib/index.js:350:20) at Object.<anonymous> (/home/chilin/mern_shopping_list/app.js:31:4) at Module._compile (node:internal/modules/cjs/loader:1103:14) ``` 1. 資料庫沒裝好或是沒啟動 * 如果是在自己電腦上安裝 MongoDB 要注意下載完預設是不啟動的(for Linux),記得先檢查 ```sh $ systemctl status mongod.service ``` 2. 後端沒有讀到你的 URI 與 DB name,建議在後端程式中輸出看看現在讀到的 DB 設定為何 * 例如 ```app.js``` 中先取得了 URI 與 DB name 才進行連接,可以多加一行看看現在讀到什麼 ```js=14 const { MONGO_URI, MONGO_DB_NAME } = config; // debug console.log(MONGO_URI) ``` * 如果還是 ```undefined``` 的話有兩種解法: * 下面註解的為原先 code 1. 手動設定所有 DB 相關變數: * ```app.js``` ```js=1 import express from 'express'; import mongoose from 'mongoose'; import path from 'path'; import cors from 'cors'; import bodyParser from 'body-parser'; import morgan from 'morgan'; // import config from './config'; import 'dotenv/config' // routes import authRoutes from './routes/api/auth'; import itemRoutes from './routes/api/items'; import userRoutes from './routes/api/users'; // const { MONGO_URI, MONGO_DB_NAME } = config; const MONGO_URI = "mongodb://localhost:27017" const MONGO_DB_NAME = "test" ``` * ```routes/api/auth.js``` * 加上第九行 ```js=1 import { Router } from 'express'; import bcrypt from 'bcryptjs'; import config from '../../config'; import jwt from 'jsonwebtoken'; import auth from '../../middleware/auth'; // User Model import User from '../../models/User'; const JWT_SECRET="sl_myJwtSecret" const router = Router(); ``` * ```middleware/auth.js``` * 加第四行 ```js=1 import jwt from 'jsonwebtoken'; import config from '../config'; const JWT_SECRET="sl_myJwtSecret" export default (req, res, next) => { ``` * ```server.js``` * 加第四行指定 port ```js=1 import app from './app'; import config from './config'; const PORT = 5000 app.listen(PORT, () => console.log(`Server started on PORT ${PORT}`)); ``` 2. 設定 env dotfile: * 這邊只以 ```app.js``` 為例子,詳細要修改的檔案請參考第一點 ```js=1 import express from 'express'; import mongoose from 'mongoose'; import path from 'path'; import cors from 'cors'; import bodyParser from 'body-parser'; import morgan from 'morgan'; // import config from './config'; import 'dotenv/config' // routes import authRoutes from './routes/api/auth'; import itemRoutes from './routes/api/items'; import userRoutes from './routes/api/users'; // const { MONGO_URI, MONGO_DB_NAME } = config; const MONGO_URI = process.env['MONGO_URI'] const MONGO_DB_NAME = process.env['MONGO_DB_NAME'] ``` * 新增 env dotfiles * ```.env``` ``` MONGO_URI=mongodb://localhost:27017 MONGO_DB_NAME=test jwtSecret=sl_myJwtSecret ``` * 測試: ```$ npm start server``` * 請確保所有操作都是正常(output ```200``` in terminal) * p.s. 這個 repo 有裝 ```nodemon``` 所以不用一直關掉重開,只要你有更動他就會重跑了 * 如果有問題歡迎直接留言!

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully